How to load a static HTML site in Google App Engine?

Do you have a tutorial? I have 3 files in my project:

  • index.html
  • index.css
  • index.js

It should be simple, but so far I am getting lost in the huge GAE documentation.

+4
source share
3 answers

You do not need to call each file separately in app.yaml, as Mark points out; instead, a simple handler is enough:

application: myapp version: main runtime: python27 api_version: 1 threadsafe: true handlers: - url: /(.*)/ static_files: \1/index.html upload: .*/index.html - url: /.* static_dir: static 

Then put your site in a directory called "static" in the directory containing app.yaml .

The first handler ensures that index.html will be provided at any time when someone requests a directory. The second handler serves all other URLs directly from the static directory.

+4
source

I really do not think that Google intends to use this service. But if you really need to serve simple static content.

You define the app.yaml file as follows:

 application: staticapp version: 1 runtime: python27 api_version: 1 threadsafe: true handlers: - url: / static_files: index.html upload: index.html - url: /index.css static_files: index.css upload: index.css -url: /index.js static_files: index.js upload: index.js 

Then use appcfg update . (assuming you are using Linux in the source directory)

+1
source

I made a simple Go app that does it very nicely. http://yourdomain.com will serve index.html, and the rest of the pages are available at http://yourdomain.com/mypage.html

Here yaml:

 application: myawesomeapp version: 1 runtime: go api_version: go1 handlers: - url: /.* script: _go_app 

Here comes the program that will serve all your static files at the root level:

 package hello import ( "net/http" ) func init() { http.HandleFunc("/", handler) } func handler(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "static/"+r.URL.Path) } 

Then drop all your static files into the / static directory, run goapp deploy and you're done.

0
source

Source: https://habr.com/ru/post/1416431/


All Articles