y-server-plugin-error
v0.0.4
Published
y-server error handle plugin
Downloads
4
Readme
y-server-plugin-error
y-server-plugin-error is a y-server plugin to handle error.
Install
npm install y-server-plugin-error
Usage
const path = require('path');
const yServer = require('y-server');
const ejsPlugin = require('y-server-plugin-ejs');
const errorPlugin = require('y-server-plugin-error');
yServer({
plugins: [
ejsPlugin({
viewDir: path.join(__dirname, './view'), // 模板根目录
renderAdapter: (result) => {
result.$render = true;
return result;
},
}),
function (app) {
app.get('/error', function (req, res, next) {
next(new Error('error msg'));
});
},
errorPlugin({
// debug: false,
views: {
'404': '404.html',
'500': '500.html',
},
}),
],
});
Notes
debug
is the switcher to show error detail.views.404
is the not found page template.views.500
is the error page template.