Bel*_*lgi 4 mime json azure http-status-code-404 angular
我有一个角度2的应用程序与简单的server.js作为node.js BE.
我已经将我的应用程序部署到Azure,我就是应用程序加载并向我显示欢迎页面.
当我到达试图通过HTTP请求读取本地JSON的组件时,我收到404错误(我在本地环境中没有收到). 
读取json的代码如下:
private ReadFromJson(path: string): Observable<string[]> {
return this._http.get(path)
.map((response: Response) => <string[]>response.json())
.do(data => console.log('All: ' + JSON.stringify(data)))
.catch(this.handleError);
}
Run Code Online (Sandbox Code Playgroud)
传递的实际路径是控制台中显示的路径.
我做了两件事:首先我确保该文件实际上是使用Azure CLI,并且它按预期存在.
其次,在查看了很多帖子后,我发现的唯一其他解决方案是按照此处的建议添加MIME类型,但这对我来说也不起作用.
我真的很想帮助理解并解决问题,欢迎任何建议!
如果您的应用只是前端(Angular)应用,那么您不再需要通过Node.js提供这些静态文件.因为默认情况下,Azure App Service已在其上安装了IIS,并且IIS可以通过执行某些配置来提供任何文件类型.所以,在这种情况下,你可以继续web.config看下面,并把它放到" site/wwwroot/dist ".
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
当您在Azure App Service上部署Node.js时,它将使用iisnode托管您的应用程序,并且您可能有一个web.config看起来像此链接中的内容的文件.
默认情况下,此配置文件假定文件/public夹中的静态文件.
<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}" />
</rule>
Run Code Online (Sandbox Code Playgroud)
所以,在将其添加到web.config之后,
<staticContent>
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
Run Code Online (Sandbox Code Playgroud)
请确保将静态文件放入/public文件中.
| 归档时间: |
|
| 查看次数: |
3545 次 |
| 最近记录: |