2017-09-14 35 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請求發送到運行的應用程序造成
相關問題