Skip to content

Commit b3726f5

Browse files
authored
Merge pull request #256 from AthennaIO/develop
feat(http): add option to just init the http server
2 parents 2debdbb + a00a83d commit b3726f5

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@athenna/core",
3-
"version": "5.20.0",
3+
"version": "5.21.0",
44
"description": "One foundation for multiple applications.",
55
"license": "MIT",
66
"author": "João Lenon <[email protected]>",

src/applications/Http.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ import { Is, Path, Module, Options } from '@athenna/common'
1515

1616
export class Http {
1717
/**
18-
* Boot the Http application.
18+
* Only initialize the server without booting it.
1919
*/
20-
public static async boot(options?: HttpOptions): Promise<ServerImpl> {
20+
public static async init(options?: HttpOptions): Promise<ServerImpl> {
2121
options = Options.create(options, {
22+
initOnly: false,
2223
host: Config.get('http.host', '127.0.0.1'),
2324
port: Config.get('http.port', 3000),
2425
routePath: Config.get('rc.http.route', Path.routes(`http.${Path.ext()}`)),
@@ -37,6 +38,20 @@ export class Http {
3738
ioc.safeUse('Athenna/Core/HttpRoute').register()
3839

3940
await server.viteReady()
41+
42+
return server
43+
}
44+
45+
/**
46+
* Boot the Http application.
47+
*/
48+
public static async boot(options?: HttpOptions): Promise<ServerImpl> {
49+
const server = await this.init(options)
50+
51+
if (options.initOnly) {
52+
return server
53+
}
54+
4055
await server.listen({ host: options.host, port: options.port })
4156

4257
if (Config.notExists('rc.bootLogs') || Config.is('rc.bootLogs', false)) {

src/types/HttpOptions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
*/
99

1010
export type HttpOptions = {
11+
/**
12+
* Only initialize the server without booting it. Useful when you want to
13+
* deploy your application in a serverless environment.
14+
*
15+
* @default false
16+
*/
17+
initOnly?: boolean
18+
1119
/**
1220
* The host where the server will run. By default Athenna will read the "http.host" config
1321
* to get this information, but you can set here and subscribe this behavior.

0 commit comments

Comments
 (0)