【问题标题】:Angular app unable to find asset files on AzureAngular 应用无法在 Azure 上找到资产文件
【发布时间】:2019-10-06 09:41:25
【问题描述】:

我刚刚通过运行 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)

【问题讨论】:

    标签: angular azure


    【解决方案1】:

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

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

    【讨论】:

    • 我应该将此文件添加到我的源文件夹并运行 ng build --prod 还是应该在构建后将它放在 dist 文件夹中?
    • 该文件应添加到您的源文件夹中,然后确保将其作为资产包含在您的应用程序中,通过 angular.json 或 angular-cli.json 文件。 >
    猜你喜欢
    • 2015-11-24
    • 2022-11-18
    • 2021-10-26
    • 2019-05-01
    • 1970-01-01
    • 2020-11-05
    • 2022-08-09
    • 2017-12-11
    • 2018-11-20
    相关资源
    最近更新 更多