0.0.4 • Published 7 years ago

y-server-plugin-error v0.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

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.

License

MIT License

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago