Node/Express 未在 500 错误页面上加载 CSS

Node/Express doesn't load CSS on 500 error page

对于我的错误页面,我使用

// 500 error
app.use(function (err, req, res, next) {
    console.log(err);
    console.log(err.stack);
    res.render("error", {
        status: err.status || 500,
        error: err,
        title: config.pageTitles.error,
        ENV: app.get('ENV')
    });
});

我的错误页面是一个 jade 模板,如下所示:

extends base
block body
    body(class="gray-bg")
        div(class="middle-box text-center animated fadeInDown")
            h1 500
            h3(class="font-bold") Internal Server Error
            div(class="error-desc")
                p   The server encountered something unexpected that didn't allow it to complete the request. We apologize.

我的其他正常页面是

extends base
block content
    #application

我的问题是当我收到 500 错误时,CSS 没有加载;但是,如果我在普通页面上加载页面 error,则会加载 CSS。似乎错误的 app.use 导致了这个。

感谢帮助

通常在未加载资产时(例如服务器 returns 资产的 404)问题与(相对)路径的使用有关。

尝试为您的 CSS 文件使用绝对路径(在您的模板中)and/or 使用浏览器的 Web 开发工具检查请求的资源路径是什么并修复适当的相对路径(例如,在适当的地方添加 .. 以获得正确的路径)。