2017-09-14 36 views
0

虽然我的应用程序在本地运行正常,我有困难的时候将其部署到蔚蓝色的Web应用程序。如何定义Azure的部署web.config文件以获得平均的应用?

的应用程序的结构如下:

  • ./index.html
  • ./app.js - 主要的node.js代码,包括快速中间件
  • ./*.js - 支持MYAPP的Node.js的代码
  • ./assets/angular - Angular.js v1.2.x
  • ./assets/bootstrap
  • ./assets/css
  • ./assets/img
  • ./views - 视图用于应用
  • state.js路由/ MyApp的/ *(例如,/ MyApp的/家,/ MyApp的/登录)。
  • 所有快递API调用来/ API/*(例如,/ API /版)

从其他来源的花絮拼凑之后,一个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的,而大部分的资产和/ index.html文件被加载(如在浏览器调试窗口中查看)之后,我得到一个“无法加载资源:服务器按照500的状态回应(内部服务器错误)“/assets/angular/app.js。

这可能是造成这个问题?此外,在Azure上部署MEAN应用程序是否有标准?这种类型的MEAN应用是否有标准的web.config?

+0

看到的问题,如果[这些步骤](https://github.com/projectkudu/kudu/wiki /疑难解答 - 节点错误)可帮助诊断问题。 –

+0

它说:“应用程序已抛出一个未捕获的异常,并终止: ReferenceError:myapp没有在对象。(D:\ home \ site \ wwwroot \ assets \ angular \ state.js:2:1) (1)定义应用程序的assets/angular/app.js没有运行(2)index.html的行 wasn' t理解(我怀疑),或者(3)在assets/angular/angularjs /中没有运行本身 – HiDefLoLife

回答

0

的内Azure的支持MEAN应用诀窍来到了几件事情:

  • 重写express.js中间件请求server.js
  • 重写angular.js URI请求的index.html
  • 重写所有静态文件请求 - 例如,Angular资产,CSS,图像等 - 按原样/直接发送到请求的URI
  • 重要的是,Azure可以通过定义的端口正确处理您的请求,程序中的express.js服务器ss.env.PORT

在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> 

就因为这一点得到了类似的问题难住了任何人,我可以推荐:

  • 您的浏览器的开发人员工具 - 例如,对于Chrome - 我能够使用控制台。日志在我的Angular应用程序中,以确定我的快速API被调用,但没有返回
  • Postman(查看express.js请求的结果),允许我查看URI请求错误代码并确定端口可能是问题
  • Azure's Kudu toolset,允许访问应用程序日志文件,它帮助我确定它是否是我的应用程序或URI请求发送到运行的应用程序造成
相关问题