1.0.11 • Published 9 months ago

route-composer v1.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Route Composer for Express.js

This is an Express.js library that makes it easy to composer routes similar to Laravel. It has the ability to group related routes and apply middleware or prefix.

Installation

npm install route-composer

Usage

import { StatusController } from '../controllers/statusController';
import { Composer } from 'route-composer';

export default Composer.group().routes([
  {
    path: '/status',
    method: 'get',
    controller: StatusController.index,
  },
]);

URL Prefixing

Prefix URLs for related routes

export default Composer
  .group()
  .prefix('/pages')
  .routes([
    {
      path: '/one',
      method: 'get',
      controller: PagesController.one,
    },
    {
      path: '/two',
      method: 'get',
      controller: (req, res) => {
        res.json({ message: 'page one' });
      },
    },
  ]);

This will produce the routes /pages/one and /pages/two

Middleware

Apply middleware to a group of routes

const authMiddleware = (
  req: Request,
  res: Response,
  next: NextFunction
) => {
  // check auth logic
  next();
};


export default Composer
  .group()
  .middleware(authMiddleware)
  .prefix('/auth')
  .routes([
    {
      path: '/login',
      method: 'get',
      controller: AuthController.login,
    },
    {
      path: '/logout',
      method: 'get',
      controller: AuthController.logout,
    },
  ]);
1.0.11

9 months ago

1.0.10

9 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago