英文:
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
处理程序没有在与给定的url
和static_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/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论