-
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.
turbopack: pass dev server address to router
- Loading branch information
1 parent
ebdc890
commit 31a0257
Showing
7 changed files
with
61 additions
and
11 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
13 changes: 13 additions & 0 deletions
13
...tes/next-dev-tests/tests/integration/next/router/middleware-api-fetch/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,13 @@ | ||
import { NextResponse } from 'next/server' | ||
import type { NextRequest } from 'next/server' | ||
|
||
export async function middleware(req: NextRequest) { | ||
const origin = new URL(req.url).origin; | ||
const res = await fetch(`${origin}/api/endpoint`); | ||
const json = await res.json(); | ||
return NextResponse.json(json); | ||
} | ||
|
||
export const config = { | ||
matcher: '/fetch-endpoint', | ||
} |
2 changes: 2 additions & 0 deletions
2
...es/next-dev-tests/tests/integration/next/router/middleware-api-fetch/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 = {} |
3 changes: 3 additions & 0 deletions
3
...-dev-tests/tests/integration/next/router/middleware-api-fetch/input/pages/api/endpoint.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,3 @@ | ||
export default function handler(_req, res) { | ||
res.status(200).json({ name: 'John Doe' }) | ||
} |
18 changes: 18 additions & 0 deletions
18
...es/next-dev-tests/tests/integration/next/router/middleware-api-fetch/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,18 @@ | ||
import { useEffect } from 'react' | ||
|
||
export default function Foo() { | ||
useEffect(() => { | ||
// Only run on client | ||
import('@turbo/pack-test-harness').then(runTests) | ||
}) | ||
|
||
return 'index' | ||
} | ||
|
||
function runTests() { | ||
it('should include custom env fields in middleware process', async () => { | ||
const res = await fetch('/fetch-endpoint') | ||
const env = await res.json() | ||
expect(env).toHaveProperty('name', 'John Doe') | ||
}) | ||
} |
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