Golang Appengine – 如何从根URL提供静态文件

huangapple go评论73阅读模式
英文:

Golang Appengine - How to serve a static file from root url

问题

我尝试将我的Go应用部署到App Engine,但它抱怨我的根URL在服务器上没有处理。我的app.yml文件设置为在访问根URL时提供index.html。在本地似乎工作正常。这种方法有什么问题吗?这是我的yaml文件。谢谢!

application: myapp-go
version: 2
runtime: go
api_version: go1

handlers:
- url: /
  static_files: js_app/index.html
  upload: js_app/uploads/.*

- url: /api/.*
  script: _go_app

- url: /javascripts
  static_dir: js_app/javascripts/

- url: /stylesheets
  static_dir: js_app/stylesheets/

- url: /templates
  static_dir: js_app/templates/

- url: /images
  static_dir: js_app/images/
英文:

I tried to deploy my go app to appengine and it complains that my root url isn't handled on the server. My app.yml file is set up to serve index.html when the root url is hit. It seems to work locally. Is there something wrong with this approach? Here's my yaml file. Thanks!

application: myapp-go
version: 2
runtime: go
api_version: go1

handlers:
- url: /
  static_files: js_app/index.html
  upload: js_app/uploads/.*

- url: /api/.*
  script: _go_app

- url: /javascripts
  static_dir: js_app/javascripts/

- url: /stylesheets
  static_dir: js_app/stylesheets/

- url: /templates
  static_dir: js_app/templates/

- url: /images
  static_dir: js_app/images/

答案1

得分: 1

处理程序没有在与给定的urlstatic_files对应的uploads目录中找到您的index.html。请改用以下方式:

handlers:
- url: /
  static_files: js_app/index.html
  upload: js_app/index.html

如果您有其他静态文件要在uploads路由下提供,我建议您将它们分开:

handlers:
- url: /
  static_files: js_app/index.html
  upload: js_app/index.html

- url: /uploads
  static_dir: js_app/uploads/
英文:

The handler is not seeing your index.html in your uploads directory that corresponds with the given url and static_files. Use this instead:

handlers:
- url: /
  static_files: js_app/index.html
  upload: js_app/index.html

If you have other static files you want to make available under the uploads route I'll suggest you separate them to be:

handlers:
- url: /
  static_files: js_app/index.html
  upload: js_app/index.html

- url: /uploads
  static_dir: js_app/uploads/

huangapple
  • 本文由 发表于 2015年7月12日 05:34:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/31362068.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定