Add kernel modules and basic kernel handling

This commit is contained in:
2021-03-07 12:51:04 -06:00
parent 94add3d471
commit fdcd80a43e
6 changed files with 56 additions and 14 deletions

View File

@@ -3,17 +3,27 @@ import {Unit} from "../lifecycle/Unit";
import {createServer, IncomingMessage, ServerResponse, Server} from "http";
import {Logging} from "./Logging";
import {Request} from "../http/lifecycle/Request";
import {HTTPKernel} from "../http/kernel/HTTPKernel";
import {PoweredByHeaderInjectionHTTPModule} from "../http/kernel/module/PoweredByHeaderInjectionHTTPModule";
import {SetSessionCookieHTTPModule} from "../http/kernel/module/SetSessionCookieHTTPModule";
@Singleton()
export class HTTPServer extends Unit {
@Inject()
protected readonly logging!: Logging
@Inject()
protected readonly kernel!: HTTPKernel
protected server?: Server
public async up() {
const port = 8000
// TODO register these by config
PoweredByHeaderInjectionHTTPModule.register(this.kernel)
SetSessionCookieHTTPModule.register(this.kernel)
await new Promise<void>((res, rej) => {
this.server = createServer(this.handler)
@@ -37,10 +47,11 @@ export class HTTPServer extends Unit {
}
public get handler() {
return (request: IncomingMessage, response: ServerResponse) => {
return async (request: IncomingMessage, response: ServerResponse) => {
const extolloReq = new Request(request, response)
extolloReq.cookies.set('testing123', {foo: 'bar', bob: 123})
extolloReq.response.send('Hi, from Extollo!!')
await this.kernel.handle(extolloReq)
await extolloReq.response.send('Hi, from Extollo!!')
}
}