-
Notifications
You must be signed in to change notification settings - Fork 26k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
776648c
commit 95603a2
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
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') | ||
}) | ||
} |