forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply experimental configs for middleware (vercel#41142)
This applies the experimental configs for testing and also fixes `set-cookie` headers from middleware/edge functions being merged unexpectedly. x-ref: [slack thread](https://vercel.slack.com/archives/CGU8HUTUH/p1664313529422279) Fixes: vercel#40820 ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md`
- Loading branch information
Showing
15 changed files
with
386 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { NextResponse } from 'next/server' | ||
|
||
export default function handler(req) { | ||
if (req.nextUrl.pathname === '/middleware-rewrite-with-slash') { | ||
return NextResponse.rewrite(new URL('/another/', req.nextUrl)) | ||
} | ||
|
||
if (req.nextUrl.pathname === '/middleware-rewrite-without-slash') { | ||
return NextResponse.rewrite(new URL('/another', req.nextUrl)) | ||
} | ||
|
||
if (req.nextUrl.pathname === '/middleware-redirect-external-with') { | ||
return NextResponse.redirect('https://example.vercel.sh/somewhere/', 307) | ||
} | ||
|
||
if (req.nextUrl.pathname === '/middleware-redirect-external-without') { | ||
return NextResponse.redirect('https://example.vercel.sh/somewhere', 307) | ||
} | ||
|
||
if (req.nextUrl.pathname.startsWith('/api/test-cookie')) { | ||
const res = NextResponse.next() | ||
res.cookies.set('from-middleware', 1) | ||
return res | ||
} | ||
|
||
return NextResponse.next() | ||
} |
13 changes: 13 additions & 0 deletions
13
test/e2e/skip-trailing-slash-redirect/app/pages/another.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,13 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Page(props) { | ||
return ( | ||
<> | ||
<p id="another">another page</p> | ||
<Link href="/"> | ||
<a id="to-index">to index</a> | ||
</Link> | ||
<br /> | ||
</> | ||
) | ||
} |
12 changes: 12 additions & 0 deletions
12
test/e2e/skip-trailing-slash-redirect/app/pages/api/test-cookie-edge.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,12 @@ | ||
import { NextResponse } from 'next/server' | ||
|
||
export const config = { | ||
runtime: 'experimental-edge', | ||
} | ||
|
||
export default function handler(req) { | ||
console.log('setting cookie in api route') | ||
const res = NextResponse.json({ name: 'API' }) | ||
res.cookies.set('hello', 'From API') | ||
return res | ||
} |
5 changes: 5 additions & 0 deletions
5
test/e2e/skip-trailing-slash-redirect/app/pages/api/test-cookie.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,5 @@ | ||
export default function handler(req, res) { | ||
console.log('setting cookie in api route') | ||
res.setHeader('Set-Cookie', 'hello=From API') | ||
res.status(200).json({ name: 'API' }) | ||
} |
13 changes: 13 additions & 0 deletions
13
test/e2e/skip-trailing-slash-redirect/app/pages/blog/[slug].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,13 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Page(props) { | ||
return ( | ||
<> | ||
<p id="blog">blog page</p> | ||
<Link href="/"> | ||
<a id="to-index">to index</a> | ||
</Link> | ||
<br /> | ||
</> | ||
) | ||
} |
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,17 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Page(props) { | ||
return ( | ||
<> | ||
<p id="index">index page</p> | ||
<Link href="/another"> | ||
<a id="to-another">to another</a> | ||
</Link> | ||
<br /> | ||
<Link href="/blog/first"> | ||
<a id="to-blog-first">to /blog/first</a> | ||
</Link> | ||
<br /> | ||
</> | ||
) | ||
} |
Oops, something went wrong.