2017-01-06 6 views
0

AzureサーバーでNodeJSアプリケーションを実行しています。すべてのAPIが適切な応答で正常に動作しています。AzureサーバーがBad Requestで応答するのはなぜですか?

今の問題は、私がGET APIのこの種を実行するときにということである。

https://demoapp.azurewebsites.net/mymenu?userId=piyush.dholariya 

必要NodeJSコードは次のとおりです。

app.get('/mymenu', function(req, res) { 
    res.status(code).send(err || result); 
}); 

要求が成功したときはいつでも、それはとの適切な応答を与えます必要な出力、今問題は要求が失敗するたびに見つかったエラーは私に応答でエラーメッセージを与えていない、それはいつも私に400コードでBad Requestを与える

ここでエラー応答を処理するにはどうすればよいですか?

答えて

1

これを次のコード行で再現できます。

enter image description here

app.get('/mymenu', function(req, res) { 
    res.status(400).send('Something wrong'); 
}); 

はこれを修正するために、我々は web.configファイルに次のタグを追加する必要があります。

<httpErrors existingResponse="PassThrough" /> 

web.configの完全なファイルは次のようになります。

<?xml version="1.0" encoding="utf-8"?> 

<configuration> 
    <system.webServer> 

      <webSocket enabled="false" /> 
      <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> 

        <!-- First we consider whether the incoming URL matches a physical file in the /public folder --> 
        <rule name="StaticContent"> 
         <action type="Rewrite" url="public{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="app.js"/> 
        </rule> 
       </rules> 
      </rewrite> 

      <!-- bin directory has no special meaning in node.js and apps can be placed in it --> 
      <security> 
       <requestFiltering> 
        <hiddenSegments> 
         <remove segment="bin"/> 
        </hiddenSegments> 
       </requestFiltering> 
      </security> 

      <!-- Make sure error responses are left untouched --> 
      <httpErrors existingResponse="PassThrough" /> 

      <iisnode watchedFiles="web.config;*.js" debuggingEnabled="false" /> 
    </system.webServer> 
</configuration> 

を、その後、あなたは応答でエラーメッセージが表示されます。

enter image description here

+0

wooowのおかげで、私はたくさんの愛する何回も、おかげで変更を持っている&私のコードを確認してください。 –

関連する問題