diff --git a/package-lock.json b/package-lock.json index 4f8adce..95fe46b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/core", - "version": "5.20.0", + "version": "5.21.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/core", - "version": "5.20.0", + "version": "5.21.0", "license": "MIT", "dependencies": { "pretty-repl": "^3.1.2", diff --git a/package.json b/package.json index 0214ec3..48e333d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/core", - "version": "5.20.0", + "version": "5.21.0", "description": "One foundation for multiple applications.", "license": "MIT", "author": "João Lenon ", diff --git a/src/applications/Http.ts b/src/applications/Http.ts index af99f3e..48f84d5 100644 --- a/src/applications/Http.ts +++ b/src/applications/Http.ts @@ -15,10 +15,11 @@ import { Is, Path, Module, Options } from '@athenna/common' export class Http { /** - * Boot the Http application. + * Only initialize the server without booting it. */ - public static async boot(options?: HttpOptions): Promise { + public static async init(options?: HttpOptions): Promise { options = Options.create(options, { + initOnly: false, host: Config.get('http.host', '127.0.0.1'), port: Config.get('http.port', 3000), routePath: Config.get('rc.http.route', Path.routes(`http.${Path.ext()}`)), @@ -37,6 +38,20 @@ export class Http { ioc.safeUse('Athenna/Core/HttpRoute').register() await server.viteReady() + + return server + } + + /** + * Boot the Http application. + */ + public static async boot(options?: HttpOptions): Promise { + const server = await this.init(options) + + if (options.initOnly) { + return server + } + await server.listen({ host: options.host, port: options.port }) if (Config.notExists('rc.bootLogs') || Config.is('rc.bootLogs', false)) { diff --git a/src/types/HttpOptions.ts b/src/types/HttpOptions.ts index 1860c9e..3e0f989 100644 --- a/src/types/HttpOptions.ts +++ b/src/types/HttpOptions.ts @@ -8,6 +8,14 @@ */ export type HttpOptions = { + /** + * Only initialize the server without booting it. Useful when you want to + * deploy your application in a serverless environment. + * + * @default false + */ + initOnly?: boolean + /** * The host where the server will run. By default Athenna will read the "http.host" config * to get this information, but you can set here and subscribe this behavior.