mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
## Feature
As the title, support `has` match, `local` that works the same with the `rewrites` and `redirects` of next.config.js on middleware config. With this PR, you can write the config like the following:
```js
export const config = {
matcher: [
"/foo",
{ source: "/bar" },
{
source: "/baz",
has: [
{
type: 'header',
key: 'x-my-header',
value: 'my-value',
}
]
},
{
source: "/en/asdf",
locale: false,
},
]
}
```
Also, fixes https://github.com/vercel/next.js/issues/39428
related https://github.com/vercel/edge-functions/issues/178, https://github.com/vercel/edge-functions/issues/179
- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`
Co-authored-by: JJ Kasper <[email protected]>
18 lines
345 B
JavaScript
18 lines
345 B
JavaScript
import { NextResponse } from 'next/server'
|
|
|
|
export default function middleware(request) {
|
|
const nextUrl = request.nextUrl.clone()
|
|
nextUrl.pathname = '/'
|
|
const res = NextResponse.rewrite(nextUrl)
|
|
res.headers.set('X-From-Middleware', 'true')
|
|
return res
|
|
}
|
|
|
|
export const config = {
|
|
matcher: [
|
|
{
|
|
source: '/hello',
|
|
},
|
|
],
|
|
}
|