Cabbage-Express is a library to quickly build controller based express applications.
Package | Version |
---|---|
Express | 4.17.3 |
Body-Parser | 1.19.2 |
TypeDi | 0.10.0 |
Reflect-Metadata | 0.1.13 |
$ npm install cabbage-express
import { CabbageApi } from 'cabbage-express'
const api = Container.get(CabbageApi)
api.configureMiddleware()
.mapControllers([
[AuthController, new AuthController()]
])
.mapEndpoints()
.listen(process.env.PORT, () => console.log(`Listening on port ${process.env.PORT}`))
@ControllerRoute("/auth")
export default class AuthController {
// Defines a GET request with no middleware
@HttpGet("/login")
async login(req: Request, res: Response) {
...
}
// Defines a POST request with the `isLoggedIn` middleware.
@HttpPost("/change_password", isLoggedIn)
async changePassword(req: Request, res: Response) {
...
}
}
GET /auth/login
POST /auth/change_password
Anyone is welcomed to contribute to Cabbage-Express. Simply clone down the repository and submit a pull-request of your desired changes.