[英]How to define a web.config file for Azure deployment for a MEAN application?
While my app runs fine locally, I'm having a difficult time deploying it to an Azure Web App. 虽然我的应用程序在本地运行良好,但将其部署到Azure Web App时遇到了困难。
The structure of the application is as follows: 该应用程序的结构如下:
After piecing together tidbits from other sources, my best guess for a web.config is as follows: 将其他来源的花絮拼凑在一起后,我对web.config的最佳猜测如下:
<handlers>
<!-- Indicates that the app.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="app.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^app.js\/debug[\/]?" />
</rule>
<rule name="Static files" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<!-- Core application files -->
<add input="{REQUEST_URI}" pattern="assets/" ignoreCase="true" />
<add input="{REQUEST_URI}" pattern="views/" ignoreCase="true" />
</conditions>
<action type="Rewrite" url="{REQUEST_URI}" />
</rule>
<rule name="Express.js API">
<match url="api/*" />
<action type="Rewrite" url="app.js"/>
</rule>
<rule name="Angular">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
Unfortunately, after publishing to Azure, while most of the assets/ and index.html file are loaded (as viewed in browser debug window), I get a "Failed to load resource: the server responded with a status of 500 (Internal Server Error)" on the /assets/angular/app.js. 不幸的是,发布到Azure之后,虽然加载了大多数asset /和index.html文件(在浏览器调试窗口中查看),但我收到“加载资源失败:服务器的响应状态为500(内部服务器错误)”上的/assets/angular/app.js。
What could be causing this issue? 是什么导致此问题? Furthermore, is there a standard for deploying MEAN apps on Azure?
此外,是否存在用于在Azure上部署MEAN应用程序的标准? Is there a standard web.config for this type of MEAN app?
是否有针对此类MEAN应用的标准web.config?
The trick for supporting MEAN applications within Azure came down to a few things: 在Azure中支持MEAN应用程序的技巧归结为以下几点:
Within server.js: 在server.js中:
// Within server.js - make sure we're listening on the proper port
server.listen(process.env.PORT, function () {
logger.info('Web server listening on port ' + process.env.PORT)
});
Then for web.config: 然后对于web.config:
<handlers>
<!-- Indicates that the app.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>
<!-- For static files, redirect to the URI -->
<rule name="Static files" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<!-- Any directory/file in the assets/ or views/ directory -->
<add input="{REQUEST_URI}" pattern="assets\/" ignoreCase="true" />
<add input="{REQUEST_URI}" pattern="views\/" ignoreCase="true" />
</conditions>
<action type="Rewrite" url="{REQUEST_URI}"/>
</rule>
<!-- For Express.js middleware API, if using api/ prefix, then use server.js -->
<rule name="Express.js URIs">
<match url="api/*" />
<action type="Rewrite" url="server.js" />
</rule>
<!-- For Angular.js URIs, rewrite to the index.html file -->
<rule name="Angular">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
And for anyone that gets stumped with a similar issue, may I recommend: 对于遇到类似问题的人,我可以建议:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.