错误:未找到 在此服务器上找不到请求的 URL /。
部署在谷歌云上的 Angular 项目名为 Angular-weather:
正如您将看到的,它具有如下 app.yaml 文件:
runtime: nodejs20
service: weather-front
handlers:
- url: /*
static_files: dist/angular-weather/index.html
upload: dist/angular-weather/index.html
- url: /(.*\.(gif|png|ico|jpg|css|js)(|\.map))$
static_files: dist/angular-weather/\1
upload: dist/angular-weather/(.*\.(gif|png|ico|jpg|css|js)(|\.map))$
执行 ng build 和 gcloud app deploy 命令后,我打开已部署的应用程序,但它找不到索引或徽标 (.ico)。
需要记住的几件事......
您的第一个处理程序非常贪婪,并且消耗了也适用于第二个处理程序的任何内容。
因此,第二个处理程序将永远不会收到任何东西。如果您想要这些处理程序,您需要先执行第二个处理程序,因此它将采用与这些特定模式匹配的任何内容,然后 /* 处理程序将采用(几乎)剩下的任何内容。
但是,您还没有为 / (即 https://my.domain.com/)定义任何处理程序
相反,请考虑为裸根放置一个处理程序,然后将所有其他处理程序传递给它们,无论它们是被引用的。 尝试以下操作:
handlers:
- url: /
static_files: dist/angular-weather/index.html
upload: dist/angular-weather/index.html
- url: /(.+)
static_files: dist/angular-weather/\1
upload: dist/angular-weather/.*
那么
https://my.domain.com/ --> index.html [第一个处理程序] https://my.domain.com/index.html --> index.html [第二个处理程序] https://my.domain.com/foo/bar.png --> foo/bar.png [第二个处理程序]