我想要定义自定义404没有找到的响应页与环回。在文档中,已经给出了回环中间件在express上的定义,但我不知道如何在回环中定义自定义错误页面。
发布于 2016-04-14 16:24:19
在middleware.json内部,从最后阶段中删除loopback#urlNotFound中间件,并使用以下内容更新它:
"final": {
"./middleware/url-not-found-handler": {}
},现在,将以下内容放在server/middleware/url-not-found-handler.js文件中
'use strict';
module.exports = function () {
//4XX - URLs not found
return function customRaiseUrlNotFoundError(req, res, next) {
res.sendFile('path to 404.html', function (err) {
if (err) {
console.error(err);
res.status(err.status).end();
}
});
};
};https://stackoverflow.com/questions/29159727
复制相似问题