Angular应用无法在Azure上找到资产文件 [英] Angular app unable to find asset files on Azure

查看:44
本文介绍了Angular应用无法在Azure上找到资产文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚通过运行ng build --prod并将其推送到git来将我的角度应用程序部署到天蓝色,但是出现了404错误,提示它找不到我在Assets文件夹中的json文件.

I've just deployed my angular app to azure by running an ng build --prod and pushing it to git but I get a 404 error saying that it cannot find my json file I have in the assets folder.

我也尝试过运行ng build --prod --base-href"./",但是直到遇到相同的错误为止.

I've also tried running ng build --prod --base-href "./" but I'm till getting the same error.

我目前正试图在api服务中获取文件,如下所示:

I'm currently trying to get the files in an api service like this:

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

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

but when I run the website on azure I get a 404 error Failed to load resource: the server responded with a status of 404 (Not Found)

推荐答案

您需要添加自己的web.config.它位于Angular的文档中:

You need to add your own web.config.Its in the documentation of Angular: https://angular.io/guide/deployment

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

这篇关于Angular应用无法在Azure上找到资产文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆