connect-router-decorators
TypeScript icon, indicating that this package has built-in type declarations

0.1.0-alpha.0 • Public • Published

connect-router-decorators

A bundle of decorators of express.Router. TS/babel supported.

Quick start

import express from 'express';
import path from 'path';
import { Router } from 'connect-router-decorators';

const app = express();
const router = new Router(app, path.resolve('./controllers'), {
  searchPattern: '**/*.{js,ts}', // default
});

const bootstrap = async () => {
  router.beforeAll((req, res, next) => {
    if (!req.startTime) {
      req.startTime = Date.now();
    }

    next();
  });

  router.afterAll((req, res, next) => {
    if (req.startTime) {
      const last = Date.now() - req.startTime;

      console.log(`Request ${req.method.toUpperCase()} - ${req.path} take ${last}ms.`);
    }

    next();
  });

  app.use(router.routes());

  app.listen(3000, () => {
    console.log(`app running on http://localhost:3000`);
  });
};

bootstrap();

TODO(s)

  • [ ] Multi-roots router support.

License

See LICENSE

Package Sidebar

Install

npm i connect-router-decorators

Weekly Downloads

1

Version

0.1.0-alpha.0

License

MIT

Unpacked Size

24.5 kB

Total Files

8

Last publish

Collaborators

  • mitscherlich36