2017-02-26 35 views
0

我正在嘗試使Azure Web App中的NodeJs上的React.js應用程序工作。 該應用程序在本地工作正常,但在Azure中,它將爲所有文件返回相同的內容。Azure上的React.js + node.js

的應用主要有3個文件:

  • 的index.html(該文件引用其他兩個)
  • bundle.js
  • styles.css的

本地打開時應用程序在瀏覽器中,index.html與其他2個文件一起提供。他們每個人都有正確的內容。

在Azure上,而是bundle.js和Styles.css中有index.html的

節點應用的內容具有此相關的配置:

app.use(express.static('dist')); 

app.get('*', function(req, res) { 
    res.sendFile(path.join(__dirname, '../dist/index.html')); 
}); 

在Azure上的Web.config文件正常的應用程序生成的。我玩了它,但沒有設法解決問題。

我的理解是,web.config意識到bundle.js和styless.css是公共文件,並且應該發送正確的請求給節點女巫應該通過上面的靜態設置來服務它們。 index.html用於任何URL,以便刷新頁面實際上有效。

你能告訴我我在這裏錯過了什麼嗎?

這裏也是web.config文件的相關部分:

<handlers> 
    <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module --> 
    <add name="iisnode" path="bin/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="^bin/app.js\/debug[\/]?" /> 
    </rule> 

    <!-- First we consider whether the incoming URL matches a physical file in the /public folder --> 
    <rule name="StaticContent"> 
     <action type="Rewrite" url="dist{REQUEST_URI}"/> 
    </rule> 

    <!-- All other URLs are mapped to the node.js site entry point --> 
    <rule name="DynamicContent"> 
     <conditions> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/> 
     </conditions> 
     <action type="Rewrite" url="bin/app.js"/> 
    </rule> 
    </rules> 
</rewrite> 

謝謝!

回答

0

我刪除了bin文件夾,作爲今晚的最後一件事。有效!

問題可能是正則表達式中的「/」字符(bin/app.js)... :(