index.js
function wrapMiddleware(fn) {
  assert(typeof fn === 'function', `express中间件必须是一个函数类型`);
  assert(fn.length >= 2, `express中间件必须至少有2个参数`);
  if (fn.length === 2) {
    return function (req, res, next) {
      let p = null;
      try {
        p = fn(req, res);
      } catch (err) {
        return next(err);
      }
      p.then(_ => next()).catch(err => next(err));
    };
  }
  return fn;
}
function wrapMiddleware(fn) {
  assert(typeof fn === 'function', `express中间件必须是一个函数类型`);
  assert(fn.length >= 2, `express中间件必须至少有2个参数`);
  if (fn.length === 2) {
    return function (req, res, next) {
      let p = null;
      try {
        p = fn(req, res);
      } catch (err) {
        return next(err);
      }
      p.then(_ => next()).catch(err => next(err));
    };
  }
  return fn;
}
封装中间件

@param {Function} fn
@return {Function}