diff --git a/src/server.ts b/src/server.ts index c02fcc8..8148f8f 100644 --- a/src/server.ts +++ b/src/server.ts @@ -21,7 +21,7 @@ export const serve = ( listeningListener?: (info: AddressInfo) => void ): ServerType => { const server = createAdaptorServer(options) - server.listen(options?.port ?? 3000, options.hostname ?? '0.0.0.0', () => { + server.listen(options?.port ?? 3000, options.hostname, () => { const serverInfo = server.address() as AddressInfo listeningListener && listeningListener(serverInfo) }) diff --git a/test/server.test.ts b/test/server.test.ts index d1cce78..d4e6f82 100644 --- a/test/server.test.ts +++ b/test/server.test.ts @@ -11,7 +11,7 @@ import { createServer as createHttp2Server } from 'node:http2' import { createServer as createHTTPSServer } from 'node:https' import { GlobalRequest, Request as LightweightRequest, getAbortController } from '../src/request' import { GlobalResponse, Response as LightweightResponse } from '../src/response' -import { createAdaptorServer } from '../src/server' +import { createAdaptorServer, serve } from '../src/server' import type { HttpBindings } from '../src/types' describe('Basic', () => { @@ -908,3 +908,19 @@ describe('Memory leak test', () => { expect(counter).toBe(0) }) }) + +describe('serve', () => { + const app = new Hono() + app.get('/', (c) => c.newResponse(null, 200)) + serve(app) + + it('should serve on ipv4', async () => { + const response = await fetch('http://localhost:3000') + expect(response.status).toBe(200) + }) + + it('should serve on ipv6', async () => { + const response = await fetch('http://[::1]:3000') + expect(response.status).toBe(200) + }) +})