Arjun Ajith
Arjun Ajith

Reputation: 1920

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

Upvotes: 1

Views: 1007

Answers (1)

icza
icza

Reputation: 418505

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, e.g.:

- 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 (e.g. 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.

Upvotes: 1

Related Questions