Skip to content

v1.0.0-next.0

Compare
Choose a tag to compare
@hoangvvo hoangvvo released this 06 Jul 04:26

This is the rewrite of next-connect. Most APIs may not be backward-compatible.

  • breaking: Drop built-in support for Express.js middleware. You can always create a tiny wrapper function to maintain this functionality. https://github.com/hoangvvo/next-connect#expressjs-compatibility
    • Remove next(err) pattern
  • improvement More straight-forward implementation and avoid patchy solutions. Now the handler will resolve based on pure promise resolution. One should expect a boost in perf as well.
  • feature Async middleware paradigm like Koa
router
  .use(async (req, res, next) => {
    const start = Date.now();
    await next(); // call next in chain
    const end = Date.now();
    console.log(`Request took ${end - start}ms`);
  })
  .use(authy)
  .use(databasey)
  .get(getty)
  .post(posty)
  • feature Forward returned values from handlers
router
  .use(async (req, res, next) => {
    return (await next()) + 1;
  })
  .use(async () => {
    return (await next()) + 2;
  })
  .use(async () => {
    return 3;
  });
console.log(await router.run(req, res));
// The above will print "6"
  • breaking Move to named export to avoid some issues with bundler. We also have full support for ESM/CJS
  • improvement Rewritten in TypeScript
  • fix in handler(), if there is no matching .method() (even if there are matchign .use()`, nothing should be executed.
  • fix onError should also be triggered when throwing in onNoMatch