Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
351 views
in Technique[技术] by (71.8m points)

Windows Azure Websites is overriding my 404 and 500 error pages in my node.js app

I am using Windows Azure Websites to host a node.js application. So far everything is great except for my custom errors. In my node app I have an error handler that renders a custom 404 and custom 500 error page just fine on my local machine. However, as soon as I publish to azure it overrides the response when I set the statusCode to anything except 200.

If I don't pass the 500 or 404 statusCode to the response then this does not happen, but I do want the status codes to make it to the browser. Locally I get my custom error page just fine:

However, on azure websites it only returns a single line of text:

The page cannot be displayed because an internal server error has occurred.

I tried creating my own web.config to override the default one with custom errors disabled but that didn't seem to have any effect. Here is my web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <customErrors mode="off" />
    </system.web>
    <system.webServer>
        <handlers>
            <add name="iisnode" path="app.js" verb="*" modules="iisnode"/>
        </handlers>
        <rewrite>
            <rules>
                <rule name="StaticContent">
                    <action type="Rewrite" url="public{REQUEST_URI}"/>
                </rule>
                <rule name="DynamicContent">
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
                    </conditions>
                    <action type="Rewrite" url="app.js"/>
                </rule>
            </rules>
        </rewrite>
        <iisnode
            debuggingEnabled="true"
            devErrorsEnabled="true"
            debuggerPathSegment="debug"
            nodeProcessCommandLine="&quot;%programfiles(x86)%
odejs
ode.exe&quot;"
            logDirectory="....LogFiles
odejs"
            watchedFiles="*.js;iisnode.yml;node_modules*;views*.jade;views*.ejb;routes*.js" />
    </system.webServer>
</configuration>

I'm not sure if iisnode (the extension for iis that routes requests to node.js) is responsible for overriding my error pages or if iis itself is responsible. Any suggestions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Well nevermind, I found the issue. If anyone else is having the same problem simply add the following under <system.webServer> in web.config:

<httpErrors existingResponse="PassThrough" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...