【发布时间】:2017-09-21 11:19:30
【问题描述】:
虽然我的应用在本地运行良好,但我很难将其部署到 Azure Web 应用。
应用程序的结构如下:
- ./index.html
- ./app.js - 主 node.js 代码,包括 Express 中间件
- ./*.js - 支持myapp的node.js代码
- ./assets/angular - Angular.js v1.2.x
- ./assets/bootstrap
- ./assets/css
- ./assets/img
- ./views - 应用程序的视图
- state.js 路由到 /myapp/*(例如,/myapp/home、/myapp/login)。
- 所有 Express API 调用均针对 /api/*(例如 /api/version)
在拼凑其他来源的花絮之后,我对 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 后,虽然加载了大部分 assets/ 和 index.html 文件(在浏览器调试窗口中查看),但我收到“加载资源失败:服务器响应状态为 500 (内部服务器错误)”在 /assets/angular/app.js 上。
什么可能导致此问题?此外,是否有在 Azure 上部署 MEAN 应用程序的标准?这种类型的 MEAN 应用是否有标准的 web.config?
【问题讨论】:
-
看看these steps能否帮助诊断问题。
-
它说“应用程序抛出了一个未捕获的异常并被终止:ReferenceError: myapp is not defined at Object.
(D:\home\site\wwwroot\assets\angular\state.js :2:1). 我猜是:(1) assets/angular/app.js,它定义了应用程序没有运行 (2) index.html 的行 不被理解(我怀疑),或者(3)angular 本身,在 assets/angular/angularjs/ 没有运行
标签: angularjs node.js azure azure-web-app-service