0.1.0 • Published 3 years ago
@zoetrope-source/router v0.1.0
@zoetrope-source/router
Decorators and express middleware for routing.
// controllers/BooksController.ts
import { Controller, Get } from '@zoetrope-source/router';
import { getBooks } from '../db/books';
import { Book } from '../models/books';
@Controller()
class BooksController {
@Get('/books')
public async getBooks(): Promise<Array<Book>> {
return await getBooks();
}
}
export default BooksController;
// index.ts
import { express as createApp } from 'express';
import router from '@zoetrope-source/router';
const app = createApp();
router(app);
Options
By default, router(...)
will look for controllers with routes to register in
a directory named controllers
relative to the file where router(...)
is
called. This director can be changed with the controllerDir
property:
router(app, { controllerDir: resolve(__dirname, '../controllers') });
0.1.0
3 years ago