【发布时间】:2016-01-22 20:54:00
【问题描述】:
Google Cloud 文档对用于我的 Node.js 应用程序的 app.yaml 文件的可用语法不是很精确。
我使用了Python documentation for GAE 中描述的语法,从中我找到了 handlers 机制:
handlers:
- url: /index.html
static_files: /public/index.html
upload: /public/index.html
我已经避免了我的 expressjs 规则来提供 /public/index.html 内容,最后我得到了 404 错误,这意味着 GAE 没有将我的页面作为静态内容提供:
$ curl -i "http://my-project/index.html"
HTTP/1.1 404 Not Found
...
您对此有任何线索吗? Node.js 与制作 API、生成动态内容有关……但我更喜欢使用 Google 后端甚至 Nginx 服务器来处理静态内容。
更新
删除前导斜杠并不能解决问题。我稍微改变了我的 app.yaml 配置:
handlers:
- url: /api/.*
secure: always
script: app.js
- url: /.*
secure: always
static_dir: public
我仍然在/index.html 上得到 404 Not found,并且得到
调用 /api/stuff 时的正确 200 OK 答案。
这是我的项目树结构:
Project root
|- app.js
|- app.yaml
|- package.json
|- public/
| `-- css/
| `-- style.css
| `-- js/
| `-- main.js
| `-- index.html
【问题讨论】:
-
您是否仍然对 Nodejs 运行时 app.yaml 中的
static_dir静态文件处理程序有问题? Dan 提供的答案是否有效(从 cmets 中似乎不清楚)?
标签: node.js google-app-engine google-cloud-platform httpserver app.yaml