首页 > 解决方案 > Angular 应用无法在 Azure 上找到资产文件

问题描述

我刚刚通过运行 ng build --prod 并将其推送到 git 将我的 Angular 应用程序部署到 azure,但我收到 404 错误,说它无法在 assets 文件夹中找到我的 json 文件。

我也尝试过运行 ng build --prod --base-href "./" 但直到遇到同样的错误。

我目前正在尝试在这样的 api 服务中获取文件:

return this.http.get('../assets/exercises.json')

但是当我在 azure 上运行网站时出现 404 错误 Failed to load resource: the server responded with a status of 404 (Not Found)

标签: angularazure

解决方案


您需要在 Angular 的文档中添加自己的 web.config.Its:https ://angular.io/guide/deployment

<staticContent><mimeMap fileExtension=".json" mimeType="application/json" /></staticContent>

推荐阅读