![](/img/trans.png)
[英]How to get the app settings value from web.config file to angular JS Controller
[英]How to define a web.config file for Azure deployment for a MEAN application?
雖然我的應用程序在本地運行良好,但將其部署到Azure Web App時遇到了困難。
該應用程序的結構如下:
將其他來源的花絮拼湊在一起后,我對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>
不幸的是,發布到Azure之后,雖然加載了大多數asset /和index.html文件(在瀏覽器調試窗口中查看),但我收到“加載資源失敗:服務器的響應狀態為500(內部服務器錯誤)”上的/assets/angular/app.js。
是什么導致此問題? 此外,是否存在用於在Azure上部署MEAN應用程序的標准? 是否有針對此類MEAN應用的標准web.config?
在Azure中支持MEAN應用程序的技巧歸結為以下幾點:
在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)
});
然后對於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>
對於遇到類似問題的人,我可以建議:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.