gpt4 book ai didi

node.js - Windows Azure 网站覆盖了我的 node.js 应用程序中的 404 和 500 错误页面

转载 作者:IT老高 更新时间:2023-10-28 21:57:48 26 4
gpt4 key购买 nike

我正在使用 Windows Azure 网站来托管 node.js 应用程序。到目前为止,除了我的自定义错误之外,一切都很好。在我的 Node 应用程序中,我有一个错误处理程序,可以在我的本地计算机上很好地呈现自定义 404 和自定义 500 错误页面。但是,一旦我发布到 azure,当我将 statusCode 设置为除 200 之外的任何值时,它就会覆盖响应。

如果我不将 500 或 404 statusCode 传递给响应,则不会发生这种情况,但我确实希望状态代码能够传递到浏览器。在本地,我很好地得到了自定义错误页面:

但是,在 azure 网站上它只返回一行文本:

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

我尝试创建自己的 web.config 来覆盖默认配置并禁用自定义错误,但这似乎没有任何效果。这是我的 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)%\nodejs\node.exe&quot;"
logDirectory="..\..\LogFiles\nodejs"
watchedFiles="*.js;iisnode.yml;node_modules\*;views\*.jade;views\*.ejb;routes\*.js" />
</system.webServer>
</configuration>

我不确定 iisnode (将请求路由到 node.js 的 iis 扩展)是否负责覆盖我的错误页面,或者 iis 本身是否负责。有什么建议吗?

最佳答案

没关系,我发现了这个问题。如果其他人遇到同样的问题,只需在 <system.webServer> 下添加以下内容即可在 web.config 中:

<httpErrors existingResponse="PassThrough" />

关于node.js - Windows Azure 网站覆盖了我的 node.js 应用程序中的 404 和 500 错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15144405/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com