简体   繁体   English

Golang Appengine-如何通过根网址提供静态文件

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

I tried to deploy my go app to appengine and it complains that my root url isn't handled on the server. 我尝试将go应用程序部署到appengine,但它抱怨我的根URL未在服务器上处理。 My app.yml file is set up to serve index.html when the root url is hit. 我的app.yml文件设置为在击中根URL时提供index.html。 It seems to work locally. 它似乎在本地工作。 Is there something wrong with this approach? 这种方法有什么问题吗? Here's my yaml file. 这是我的Yaml文件。 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/

The handler is not seeing your index.html in your uploads directory that corresponds with the given url and static_files . 处理程序未在与给定urlstatic_files对应的uploads目录中看到index.html 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: 如果您要在uploads路径下提供其他静态文件,建议您将它们分开:

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

- url: /uploads
  static_dir: js_app/uploads/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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