2016-10-27 2 views
0

Azure Appサービスとして実行されているエクスプレスベースのnode.jsアプリケーションがあります。 他のウェブサイトのコンテンツを処理することができます。ウェブサイトのURLはリクエストURLの一部として渡す必要があります。たとえば、アプリがhttp://myapp.comで実行され、処理したいウェブサイトがhttp://example.comの場合、URLはhttp://myapp.com/process/http://example.comです。 私はローカルでアプリケーションを実行すると、処理は動作しますが、私はそれを展開するとき、それは物理的なパスとしてURLを解決しようとするため、IISは、アプリケーション・プロセスに要求を聞かせていないので、次のエラーログを提供します。Azure App Service上のIISは、実行中のノードアプリケーションがそれを処理するのではなく、URLを物理パスとして解決します。

IIS Error message サーバーの応答がThe page cannot be displayed because an internal server error has occurred.であるため、リクエストは私のアプリケーションでは処理されません。エラーを処理するようにexpressを設定しましたが。

リクエストURLにはプロトコルが含まれていますが、プロトコルを除外するにはapiを変更するのは望ましくないためです。

私は、URL書き換えルールを何も成功せずに変更しようとしました。現在、私は、アプリケーションの実行中の他の部分を維持するために、次の、デフォルトのweb.configファイルを使用します。

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.webServer> 
    <webSocket enabled="false" /> 
    <handlers> 
     <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module --> 
     <add name="iisnode" path="src/server/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="^src/server/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="src/server/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" /> 

    </system.webServer> 
</configuration> 

だから私の目標は、IISが自分のアプリケーションからの要求を処理させることです。要求からプロトコルを削除せずに可能ですか?


UPDATE:パスがURLエンコードされた場合でも、これは、発生したため、http://myapp.com/process/http%3A%2F%2Fexample.comがちょうど同じ出力を生成します。

答えて

0

URLの文字列全体を追加のリクエストURLパターンで設定できます。例えば。

あなたはフォーマットの処理対象のURLとリクエストURLを生成します。http://myapp.com/process/?process_url=http://example.com

次に、あなたのようなあなたのexpressjsアプリケーション内のURL文字列を取得することができます

app.get('/process', function(req, res, next){ 
    res.json(req.query.process_url); 
}); 
関連する問題