问题描述
我配置了两个服务,其中一个是默认服务。但是通过 DNS 查询 https://gcpdev.company.com/one
服务时,却无法访问到项目文件。例如:
如果我直接输入这个网址,会返回 500 错误:
https://gcpdev.company.com/vendor-es2017.65ff9b5300ddf6707a5c.js
正确打开文件的是:
https://gcpdev.company.com/one/vendor-es2017.65ff9b5300ddf6707a5c.js
我的配置有问题吗?这些是 default
项目的文件:
dispatch.yaml
dispatch:
- url: "gcpdev.company.com/one/*"
service: default
- url: "gcpdev.company.com/two/*"
service: two-ui
runtime: nodejs12
service: default
handlers:
- url: /one/(.*\.(gif|png|jpg|less|json|woff|woff2|ttf|eot|scss|css|js|ico|svg)(|\.map))$
static_files: dist/\1
upload: dist/(.*)(|\.map)
- url: /one/assets/data/appConfig.json
static_files: dist/assets/data/appConfig.json
upload: dist/assets/data/appConfig.json
- url: /one/(.*)
static_files: dist/index.html
upload: dist/index.html
对于 two-ui
项目,我有相同的 dispatch.yaml
和类似的 app.yaml
:
runtime: nodejs12
service: two-ui
handlers:
- url: /two/(.*\.(gif|png|jpg|less|json|woff|woff2|ttf|eot|scss|css|js|ico|svg)(|\.map))$
static_files: dist/\1
upload: dist/(.*)(|\.map)
- url: /two/assets/data/appConfig.json
static_files: dist/assets/data/appConfig.json
upload: dist/assets/data/appConfig.json
- url: /two/(.*)
static_files: dist/index.html
upload: dist/index.html
解决方法
您的调度规则提到您必须使用:
gcpdev.company.com/one/*
gcpdev.company.com/two/*
然后,预计对 gcpdev.company.com/*
的调用会失败。没有任何规则规定如何使用该模式。
关于:
正确打开文件的是:
https://gcpdev.company.com/one/vendor-es2017.65ff9b5300ddf6707a5c.js
非常值得一看Examples:
例如:
dispatch:
# Default service serves the typical web resources and all static resources.
- url: "*/favicon.ico"
service: default**strong text**
如果您想提供没有 /one/*
和 /two/*
模式的静态文件,您可能需要添加与上述类似的内容。
关于如何在您的服务上提供静态文件,检查 Handlers element 是下一步。我的建议是首先关注 dispatcher
,然后关注 app.yaml
中的处理程序。