【问题标题】:Node/Express doesn't load CSS on 500 error pageNode/Express 不会在 500 错误页面上加载 CSS
【发布时间】:2016-01-08 21:12:20
【问题描述】:

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

// 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 导致了这种情况。

感谢帮助

【问题讨论】:

  • 检查所有相对路径以确保它们指向它们应该指向的位置

标签: javascript html css node.js pug


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2021-09-05
    • 1970-01-01
    • 2016-06-08
    • 2011-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-07
    相关资源
    最近更新 更多