Node/Express没有't在500错误页面上加载CSS

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

本文关键字:错误 CSS 加载 Express 没有 Node      更新时间:2023-09-26

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

// 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')
    });
});

我的错误页面是一个翡翠模板,看起来:

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 IS。似乎是错误的app.use导致了这种情况。

感谢的帮助

通常,当没有加载资产时(例如,服务器为资产返回404),问题与使用(相对)路径有关。

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