Skip to content

Commit c982a9e

Browse files
committed
feat: enhance HonoHttpServer to track listening port and update logging
1 parent d9aa1ff commit c982a9e

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

packages/plugins/plugin-hono-server/src/adapter.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { serveStatic } from '@hono/node-server/serve-static';
1616
export class HonoHttpServer implements IHttpServer {
1717
private app: Hono;
1818
private server: any;
19+
private listeningPort: number | undefined;
1920

2021
constructor(
2122
private port: number = 3000,
@@ -115,15 +116,21 @@ export class HonoHttpServer implements IHttpServer {
115116
this.app.get('/*', serveStatic({ root: this.staticRoot }));
116117
}
117118

119+
const targetPort = port || this.port;
118120
this.server = serve({
119121
fetch: this.app.fetch,
120-
port: port || this.port
122+
port: targetPort
121123
}, (info) => {
124+
this.listeningPort = info.port;
122125
resolve();
123126
});
124127
});
125128
}
126129

130+
getPort() {
131+
return this.listeningPort || this.port;
132+
}
133+
127134
// Expose raw app for scenarios where standard interface is not enough
128135
getRawApp() {
129136
return this.app;

packages/plugins/plugin-hono-server/src/hono-plugin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ export class HonoServerPlugin implements Plugin {
107107
ctx.logger.info('Starting HTTP server', { port });
108108

109109
await this.server.listen(port);
110+
111+
const actualPort = this.server.getPort();
110112
ctx.logger.info('HTTP server started successfully', {
111-
port,
112-
url: `http://localhost:${port}`
113+
port: actualPort,
114+
url: `http://localhost:${actualPort}`
113115
});
114116
});
115117
}

0 commit comments

Comments
 (0)