I am running a Node.js 0.10.15 & Express app on Azure Websites and am having a problem sending 404s when someone enters an invalid URL. I am getting the generic The page cannot be displayed because an internal server error has occurred.
error when I attempt to access an invalid URL.
Here is the code at the end my app.js
file that sends the 404 page:
app.get('/*', function(req, res) { res.status(404).sendfile('public/404.html'); });
The strange bit is that Express seems to be properly sending the 404 along with the HTML file when I run my server locally, but when it's running on Azure it chokes and doesn't give me a useful error. The logs make it appear that the request worked as expected:
[Thu, 24 Oct 2013 01:10:39 GMT] "GET /asdfsadf HTTP/1.1" 404 - "-" "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36"
I suspect the problem somehow lies in my web.config
file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
<staticContent>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".woff" mimeType="application/x-woff" />
<mimeMap fileExtension=".ttf" mimeType="application/x-woff" />
</staticContent>
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="DynamicContent">
<match url="/*" />
<action type="Rewrite" url="app.js"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I also have logging turned on with the iisnode.yml
file:
loggingEnabled: true
devErrorsEnabled: true
Also, you can see my dev working branch over at GitHub