简体   繁体   中英

Static files not serving when uploaded in Google app engine (SDK Go)

I was trying to use google app engine cloud space. My program is running without any problem in localhost, but when I tries to host it in google app engine, static files are not served. The app.yaml is as follows:

application: myTestApp-nn34322
version: 1
runtime: go
threadsafe: true
api_version: go1

handlers:
- url: /static/css
  static_dir: ../static/css
  mime_type: "text/css"

- url: /static/js
  static_dir: ../static/js
  mime_type: "text/javascript"

- url: /static/images
  static_dir: ../static/images

- url: /.*
  script: _go_app

You should put every static resources under the same folder where you put your app.yaml file, else they won't get uploaded to AppEngine.

So you should put your static folder next to app.yaml , and then of course the correct path is simply static/xxx , eg:

- url: /static/css
  static_dir: static/css
  mime_type: "text/css"

- url: /static/js
  static_dir: static/js
  mime_type: "text/javascript"

- url: /static/images
  static_dir: static/images

Note:

If you intend to use these static files from your Go app too (eg you want to read their content), that requires special handling because resources matched by static file patterns will not be copied to the application after uploading (static files are served by separate servers). For details, see Google App Engine Golang no such file or directory . Basically you either have to duplicate the static files, or provide the application_readable option to the static file handler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM