UNPKG

@tsed/platform-http

Version:
49 lines (48 loc) 1.73 kB
import { configuration, constant, inject, injectable } from "@tsed/di"; import { $on } from "@tsed/hooks"; import { application } from "../fn/application.js"; import { createHttpServer } from "../utils/createHttpServer.js"; import { createHttpsServer } from "../utils/createHttpsServer.js"; import { Platform } from "./Platform.js"; import { PlatformApplication } from "./PlatformApplication.js"; import { PlatformHandler } from "./PlatformHandler.js"; export class PlatformAdapter { constructor() { this.app = inject(PlatformApplication); const platformApp = inject(PlatformApplication); const { app, callback } = this.createApp(); platformApp.rawApp = app; platformApp.rawCallback = callback; $on("$afterInvoke", PlatformAdapter, () => { configuration().set("PLATFORM_NAME", constant("PLATFORM_NAME") || this.NAME); }); } getServers() { const app = application(); return [createHttpServer(app.callback()), createHttpsServer(app.callback())].filter(Boolean); } onInit() { return Promise.resolve(); } beforeLoadRoutes() { return Promise.resolve(); } afterLoadRoutes() { return Promise.resolve(); } /** * Map handler to the targeted framework */ mapHandler(handler, layer) { return handler; } /** * Return the multipart middleware * @param options * @deprecated use inject("MULTER_MODULE")?.get(options) instead */ multipart(options) { return inject(Symbol.for("MULTER_MODULE"))?.get(options); } } injectable(PlatformAdapter).imports([PlatformApplication, Platform, PlatformHandler]).alias("PlatformAdapter");