4.3.0 • Published 2 years ago
sbx-http-lib v4.3.0
Sbx Http
Install
npm i bunyan inversify
npm i git+ssh://git@gitlab.com:stackbox-group/libs/sbx-http.git#1.0.0
Sample
import * as http from "http";
import { Container } from "inversify";
import * as Logger from "bunyan";
import {
createHttpHandler,
RequestResponseLogger,
Controller,
Context,
Get
} from "sbx-http";
const di = new Container({ autoBindInjectable: true, defaultScope: "Request" });
const log = Logger.createLogger({ name: "sample" });
@Controller("/hello")
class TestController {
@Get("/v1")
async test(ctx: Context) {
ctx.body = {
message: "world"
};
}
}
const handler = createHttpHandler()({
applicationName: "sample-app",
applicationVersion: "1.0.0",
compress: true,
controllers: [TestController],
di,
isHealthy: () => true,
log,
middlewares: [RequestResponseLogger({})],
onRequestCompleted: (method, prefix, path, time) => {
log.info(`Timing: ${method} ${prefix} - ${path} = ${time} ms`);
}
});
http.createServer(handler).listen(3000);