yggdrasil-express
v2.0.3
Published
Express with InversifyJS integration
Downloads
2
Readme
Yggdrasil Server
Project which combines express and inversify.
Requirments
Projects which use this library must also use InversifyJS
Guide
Creating a RequestHandler which contains your Router logic.
import 'reflect-meta';
import * as express from 'express';
import {RequestHandler, ExpressRequestHandler, Get} from 'yggdrasil-express';
import {injectable} from 'inversify';
@RequestHandler('/')
@injectable()
class TestController implements ExpressRequestHandler {
@Get('/')
public testMethod(response: express.Response): string {
return 'Random Value';
}
@Get('/test')
public testMethod2(response: express.Response): Promise<string> {
return Promise.resolve('TestValue');
}
}
Defining the Controller in the IoC Container:
import {Container} from 'inversify';
import {Types, ExpressRequestHandler} from 'yggdrasil-express';
import {TestController} from './path-to-my-controller';
function start() {
const container = new Container();
container.bind<ExpressRequestHandler>(Types.REQUEST_HANDLER).to(TestController).whenTargetName('TestController');
const app = new YggdrasilServerBuilder(container).build();
app.listen(8000, (err) => {
if (err) {
console.log(err);
} else {
console.log('Started');
}
});
}
start();