对于我的错误页面,我使用
// 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
会导致此问题。
感谢帮助
最佳答案
通常,当 Assets 未加载时(例如,服务器为 Assets 返回 404),问题与(相对)路径的使用有关。
尝试对 CSS 文件使用绝对路径(在模板中)和/或使用浏览器的 Web 开发工具检查所请求的资源路径并修复适当的相对路径(例如,在适当的位置添加 ..
以获取正确的路径)。
关于javascript - Node/Express 不会在 500 错误页面上加载 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34686134/