- Controller decorators from routing-controllers
- Dependency injection container from inversify
- Logging based on log4js
- Database support based on typeorm
- Modules support
- Unified AJAX error responses
Performance tests for routing-controllers, typeorm, log4js.
Bootstrap:
import { Container } from 'inversify';
import { Connection, getRepository, Repository } from 'typeorm';
import {
Module,
WebApplication,
ClusteredWebApplication,
Environment,
middlewares,
} from '@c7s/node-ts-framework';
import { Type } from './Type';
export class AppModule extends Module {
public async initDiContainer(container: Container) {
container.bind<Connection>(Type.DbConnection)
.toConstantValue(await (new components.DbConnectionFactory).create([this]));
}
protected get baseDirectory() {
return __dirname;
}
}
const modules = [new AppModule];
const app = Environment.Development === process.env.PROJECT_ENV ?
new WebApplication(modules, [middlewares.ErrorHandlingMiddleware]) :
new ClusteredWebApplication(modules, [middlewares.ErrorHandlingMiddleware]);
app.run();
Controller looks like:
@JsonController('/client')
export class ClientController {
@di.inject(Type.ClientDataRepository)
protected clientDataRepository!: Repository<Client>;
@Post('/')
@HttpCode(201)
public async create(
@BodyParam('client', { required: true }) clientForm: CreateClientForm,
@Res() response: Response,
) {
}
}