Skip to content

Commit f87971e

Browse files
Fix display banner when using node adapter (#245)
* fix(banner): display banner when using node adapter The `@elysiajs/node` adapter does not pass the `server` object into the `onStart` hook, causing the startup banner to be skipped. This fix adds a fallback to extract port and hostname from environment variables (`PORT` and `HOST`) and defaults to `3000`/`localhost` if the `server` object is undefined. Fixes #244 (Follow-up to #231) Co-authored-by: Noppakorn Kaewsalabnil <PunGrumpy@users.noreply.github.com> * Add regression test for onStart when server is undefined (#246) - Extract createOnStartHandler from index.ts for testability - Add test that simulates Node adapter path (server undefined) - Verify process.env.HOST and process.env.PORT are used correctly - Assert startup banner is emitted with expected URL - Clean up process.env and restore console spies Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Noppakorn Kaewsalabnil <PunGrumpy@users.noreply.github.com> * fix(logixlysia): specify return type for onStart hook Updated the onStart hook in the logixlysia function to explicitly define the return type as void, enhancing type safety and clarity in the codebase. * refactor(logixlysia): remove redundant onStart test and clean up imports Eliminated the test for the onStart handler when the server is undefined, as it was deemed unnecessary. Cleaned up imports by removing the createOnStartHandler and spyConsole references, streamlining the test file. * refactor(logixlysia): remove createOnStartHandler function Eliminated the createOnStartHandler function and its associated type definitions from index.ts to streamline the codebase. This change simplifies the logic for starting the server by directly handling the server context within the logixlysia function. --------- Co-authored-by: Noppakorn Kaewsalabnil <PunGrumpy@users.noreply.github.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent 8bd7d04 commit f87971e

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

.changeset/clean-candies-prove.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"logixlysia": patch
3+
---
4+
5+
Fix display banner when using node adapter

packages/logixlysia/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,14 @@ export const logixlysia = (options: Options = {}): Logixlysia => {
6161
.state('logger', logger)
6262
.state('pino', logger.pino)
6363
.state('beforeTime', BigInt(0))
64-
.onStart(({ server }) => {
64+
.onStart(({ server }): void => {
6565
if (server) {
6666
startServer(server, options)
67+
} else {
68+
// Node adapter fallback
69+
const port = Number(process.env.PORT) || 3000
70+
const hostname = process.env.HOST || 'localhost'
71+
startServer({ port, hostname, protocol: 'http' }, options)
6772
}
6873
})
6974
.onRequest(({ store }) => {

0 commit comments

Comments
 (0)