-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
x-forwarded-*
headers to turbopack renders (#50012)
This PR forwards the [new `ServerInfo`](vercel/turbo#5018) struct to Turbopack's rendering processes, allowing it to initialize the requesting headers with the `x-forwarded-*` headers. These headers, and `x-forwarded-proto` in particular, are necessary for [NextAuth to work](https://github.com/nextauthjs/next-auth/blob/f62c0167/packages/next-auth/src/core/index.ts#L73-L76). These headers are initialized in the non-turbo server via [`http-proxy`](https://github.com/http-party/node-http-proxy/blob/9b96cd72/lib/http-proxy/passes/web-incoming.js#L58-L86). Fixes WEB-1064
- Loading branch information
1 parent
702eb17
commit 3558208
Showing
15 changed files
with
108 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...t-dev-tests/tests/integration/next/router/middleware-forwarded-header/input/middleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { NextResponse } from 'next/server' | ||
import type { NextRequest } from 'next/server' | ||
|
||
export function middleware(request: NextRequest) { | ||
const headers = request.headers | ||
return NextResponse.json({ | ||
host: headers.get('x-forwarded-host'), | ||
ip: headers.get('x-forwarded-ip'), | ||
port: headers.get('x-forwarded-port'), | ||
proto: headers.get('x-forwarded-proto'), | ||
}) | ||
} | ||
|
||
export const config = { | ||
matcher: '/headers', | ||
} |
2 changes: 2 additions & 0 deletions
2
...-dev-tests/tests/integration/next/router/middleware-forwarded-header/input/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/** @type {import('next').NextConfig} */ | ||
module.exports = {} |
19 changes: 19 additions & 0 deletions
19
...-dev-tests/tests/integration/next/router/middleware-forwarded-header/input/pages/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useTestHarness } from '@turbo/pack-test-harness' | ||
|
||
export default function Foo() { | ||
useTestHarness(runTests) | ||
|
||
return 'index' | ||
} | ||
|
||
function runTests() { | ||
it('should stream middleware response from node', async () => { | ||
const res = await fetch('/headers') | ||
const json = await res.json() | ||
|
||
const { host, port, proto } = json | ||
expect(host).toBe(`localhost:${port}`) | ||
expect(port).toMatch(/\d+/) | ||
expect(proto).toBe('http') | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters