File tree Expand file tree Collapse file tree
packages/plugins/plugin-hono-server/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import { serveStatic } from '@hono/node-server/serve-static';
1616export 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 ;
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments