mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
We recommend users avoid relying on Middleware unless no other options exist. Our goal is to give them APIs with better ergonomics so they can achieve their goals without Middleware. The term “middleware” often confuses users with Express.js middleware, which can encourage misuse. To clarify our direction, we are renaming the file convention to “proxy.” This highlights that we are moving away from Middleware, breaking down its overloaded features, and making the Proxy clear in its purpose. `proxy.js` should be a drop-in replacement for `middleware.js` for its features, but ONE thing: ```diff - export function middleware + export function proxy ``` Codemod: https://github.com/vercel/next.js/pull/84127 --------- Co-authored-by: Benjamin Woodruff <[email protected]>
35 lines
1008 B
TypeScript
35 lines
1008 B
TypeScript
/* eslint-env jest */
|
|
import path from 'path'
|
|
import { nextTestSetup, FileRef } from 'e2e-utils'
|
|
|
|
describe('app dir - with proxy in src dir', () => {
|
|
const { next } = nextTestSetup({
|
|
files: {
|
|
'src/app': new FileRef(path.join(__dirname, 'app')),
|
|
'next.config.js': new FileRef(path.join(__dirname, 'next.config.js')),
|
|
'src/proxy.js': `
|
|
import { NextResponse } from 'next/server'
|
|
import { cookies } from 'next/headers'
|
|
|
|
export async function proxy(request) {
|
|
const cookie = (await cookies()).get('test-cookie')
|
|
return NextResponse.json({ cookie })
|
|
}
|
|
`,
|
|
},
|
|
})
|
|
|
|
it('works without crashing when using RequestStore', async () => {
|
|
const browser = await next.browser('/')
|
|
await browser.addCookie({
|
|
name: 'test-cookie',
|
|
value: 'test-cookie-response',
|
|
})
|
|
await browser.refresh()
|
|
|
|
const html = await browser.eval('document.documentElement.innerHTML')
|
|
|
|
expect(html).toContain('test-cookie-response')
|
|
})
|
|
})
|