Search code examples
node.jsazureiisiisnode

IIS returns 500 when Node app returns a 4xx


I have also asked this on the iisnode github project

I am using IISNode via a Windows Azure Website.

If my Node app returns a 2xx status code (200, 201, etc), then all is well and works as expected.

if my Node app returns a 4xx status code, for example: response.send(404, "not found") (I am using Restify) then I get a 500 sent to the client and the body is simply "The page cannot be displayed because an internal server error has occurred."

If I do azure site log tail <sitename>, then when the 500 gets sent to the client, the log contains HTML of a 404.

...
<body> 
<div id="content"> 
<div class="content-container"> 
<h3>HTTP Error 404.0 - Not Found</h3> 
<h4>The resource you are looking for has been removed, had its name changed,
or is temporarily unavailable.</h4> 
</div> 
...

I really just want IISNode/IIS to take my 404 and send it on down to the client. This is also true of 401s, 409s, etc. They all cause a 500 to get sent instead.

I have tried <customErrors mode="off" /> and <httpErrors existingResponse="passThrough" /> in my web.config to no avail. Here is my web.config now:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <customErrors mode="off" />
  </system.web>
  <system.webServer>         
    <httpErrors existingResponse="PassThrough" />
    <staticContent>
       <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
       <mimeMap fileExtension=".ico" mimeType="image/x-icon" />
    </staticContent>
    <handlers>
      <add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>
        <rule name="DynamicContent">
           <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
           </conditions>
           <action type="Rewrite" url="server.js"/>
           <match url="/*" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

For what it's worth, I can't get IISnode to do anything but return 200s from my node app. Trying to get IIS to serve my static files, enable node-inspector, or really any of the more interesting IISNode features cause a 500 for me. No idea why, and would love to get past it!

Similar StackOverflow Questions

this question is pretty much exactly my problem. Except that <httpErrors existingResponse="PassThrough" /> does not work for me. I feel like I have something more fundamentally wrong with my IISNode setup, so if anyone has any ideas on things to try I'm all ears.


Solution

  • for some reason the following section in your config is causing this issue:

    <staticContent>
        <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
        <mimeMap fileExtension=".ico" mimeType="image/x-icon" />
    </staticContent>
    

    As a workaround, remove this section if possible and retry. I will investigate why this section is causing this issue.