File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ export const serve = (
2121 listeningListener ?: ( info : AddressInfo ) => void
2222) : ServerType => {
2323 const server = createAdaptorServer ( options )
24- server . listen ( options ?. port ?? 3000 , options . hostname ?? '0.0.0.0' , ( ) => {
24+ server . listen ( options ?. port ?? 3000 , options . hostname , ( ) => {
2525 const serverInfo = server . address ( ) as AddressInfo
2626 listeningListener && listeningListener ( serverInfo )
2727 } )
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import { createServer as createHttp2Server } from 'node:http2'
1111import { createServer as createHTTPSServer } from 'node:https'
1212import { GlobalRequest , Request as LightweightRequest , getAbortController } from '../src/request'
1313import { GlobalResponse , Response as LightweightResponse } from '../src/response'
14- import { createAdaptorServer } from '../src/server'
14+ import { createAdaptorServer , serve } from '../src/server'
1515import type { HttpBindings } from '../src/types'
1616
1717describe ( 'Basic' , ( ) => {
@@ -908,3 +908,19 @@ describe('Memory leak test', () => {
908908 expect ( counter ) . toBe ( 0 )
909909 } )
910910} )
911+
912+ describe ( 'serve' , ( ) => {
913+ const app = new Hono ( )
914+ app . get ( '/' , ( c ) => c . newResponse ( null , 200 ) )
915+ serve ( app )
916+
917+ it ( 'should serve on ipv4' , async ( ) => {
918+ const response = await fetch ( 'http://localhost:3000' )
919+ expect ( response . status ) . toBe ( 200 )
920+ } )
921+
922+ it ( 'should serve on ipv6' , async ( ) => {
923+ const response = await fetch ( 'http://[::1]:3000' )
924+ expect ( response . status ) . toBe ( 200 )
925+ } )
926+ } )
You can’t perform that action at this time.
0 commit comments