1.1.0 • Published 5 years ago

@gliluaume/deco-router v1.1.0

Weekly downloads
5
License
ISC
Repository
github
Last release
5 years ago

Deco-router

Use decorator to make an express router.

Use decorator

Methods of controllers are decorated with route they respond to:

import { Get } from '../router'

export class Room {
    @Get('/')
    public get() {
        return { nom: 'Roger' }
    }
}

Express application ask decorators lib to bind function to express app:

Application structure:

.
├── app.ts
├── controllers
│   ├── index.ts
│   └── Tester.ts
└── server.ts

where controllers are exposed by index.ts, app.ts looks like:

import express from 'express';
import { Express } from 'express';
import { bindApp } from 'deco-router';

// requiring controllers loads decorators
require('./controllers');

const app: Express = express();

// bind router to express application
bindApp(app);

export default app;

See test for a running example (npm run serve).

Global handling

Decorator could be used to handle globally:

  • errors
  • logging
  • access rights