import LifecycleUnit from '../lifecycle/Unit.ts' import {Unit} from '../lifecycle/decorators.ts' import Kernel from '../http/kernel/Kernel.ts' import {Logging} from '../service/logging/Logging.ts' import {serve} from '../external/http.ts' import {Request} from '../http/Request.ts' @Unit() export default class HttpServer extends LifecycleUnit { protected _server: any // TODO replace with more specific type constructor( protected readonly kernel: Kernel, protected readonly logger: Logging, ) { super() } public async up() { this._server = serve({ port: 8000 }) this.logger.success(`HTTP/S server listening on port 8000!`) for await ( const native_request of this._server ) { let req: Request = this.make(Request, native_request) req = await this.kernel.handle(req) req.response.send() } } }