Skip to content

Commit ae4285a

Browse files
fix: pass correct domain to server (#144)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent f149e89 commit ae4285a

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/run/handlers/server.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ export default async (request: Request) => {
2323
tagsManifest = await getTagsManifest()
2424

2525
const { getMockedRequestHandlers } = await import('../next.cjs')
26+
const url = new URL(request.url)
27+
2628
;[nextHandler] = await getMockedRequestHandlers({
27-
port: 3000,
28-
hostname: 'localhost',
29+
port: Number(url.port) || 443,
30+
hostname: url.hostname,
2931
dir: process.cwd(),
3032
isDev: false,
3133
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { NextResponse } from 'next/server'
2+
3+
export async function GET(request) {
4+
return NextResponse.json({ url: request.url })
5+
}

tests/integration/simple-app.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,12 @@ test<FixtureTestContext>('stale-while-revalidate headers should be normalized to
8484
const index = await invokeFunction(ctx, { url: '/' })
8585
expect(index.headers?.['netlify-cdn-cache-control']).toContain('stale-while-revalidate=31536000')
8686
})
87+
88+
test<FixtureTestContext>('handlers receive correct site domain', async (ctx) => {
89+
await createFixture('simple-next-app', ctx)
90+
await runPlugin(ctx)
91+
const index = await invokeFunction(ctx, { url: '/api/url' })
92+
const data = JSON.parse(index.body)
93+
const url = new URL(data.url)
94+
expect(url.hostname).toBe('example.netlify')
95+
})

0 commit comments

Comments
 (0)