1fbbba6ffe
This serves to start the transition of replacing the following: - Replace `BaseNextRequest`, `WebNextRequest`, and `NodeNextRequest` with `NextRequest` - Replace `BaseNextResponse`, `WebNextResponse`, and `NodeNextResponse` with `Response` This will currently only apply to app routes, enabling the following: ```ts //////////////////////////////////////////////////////////////////////////////// // Use `Request` and `Response` //////////////////////////////////////////////////////////////////////////////// import { NextRequest, NextResponse } from 'next/server' export function GET(request: Request): Response { return new Response( JSON.stringify({ hello: request.headers.get('user-agent'), }), { headers: { 'content-type': 'application/json' } } ) } //////////////////////////////////////////////////////////////////////////////// // Use `NextRequest` and `NextResponse` //////////////////////////////////////////////////////////////////////////////// import { NextRequest, NextResponse } from 'next/server' export function GET(request: NextRequest): NextResponse { return NextResponse.json({ hello: request.headers.get('user-agent') }) } //////////////////////////////////////////////////////////////////////////////// // Use `NextRequest` and `Response` //////////////////////////////////////////////////////////////////////////////// import { NextRequest, NextResponse } from 'next/server' // `NextRequest` extends `Request`. export function GET(request: NextRequest): Response { return new Response( JSON.stringify({ hello: request.headers.get('user-agent') }), { headers: { 'content-type': 'application/json' } } ) } //////////////////////////////////////////////////////////////////////////////// // Use `NextRequest`, `NextResponse`, and `Response` //////////////////////////////////////////////////////////////////////////////// import { NextRequest, NextResponse } from 'next/server' export function GET(request: NextRequest): Response { // `NextResponse` extends `Response`. return NextResponse.json({ hello: request.headers.get('user-agent') }) } //////////////////////////////////////////////////////////////////////////////// // Use `Request` and `NextResponse` //////////////////////////////////////////////////////////////////////////////// import { NextRequest, NextResponse } from 'next/server' export function GET(request: Request): NextResponse { return NextResponse.json({ hello: request.headers.get('user-agent') }) } ``` fix NEXT-713
31 lines
784 B
TypeScript
31 lines
784 B
TypeScript
import { createNextDescribe } from 'e2e-utils'
|
|
|
|
createNextDescribe(
|
|
'app-routes-trailing-slash',
|
|
{
|
|
files: __dirname,
|
|
},
|
|
({ next }) => {
|
|
it.each(['edge', 'node'])(
|
|
'should handle trailing slash for %s runtime',
|
|
async (runtime) => {
|
|
let res = await next.fetch(`/runtime/${runtime}`, {
|
|
redirect: 'manual',
|
|
})
|
|
|
|
expect(res.status).toEqual(308)
|
|
expect(res.headers.get('location')).toEndWith(`/runtime/${runtime}/`)
|
|
|
|
res = await next.fetch(`/runtime/${runtime}/`, {
|
|
redirect: 'manual',
|
|
})
|
|
|
|
expect(res.status).toEqual(200)
|
|
await expect(res.json()).resolves.toEqual({
|
|
url: `/runtime/${runtime}/`,
|
|
nextUrl: `/runtime/${runtime}/`,
|
|
})
|
|
}
|
|
)
|
|
}
|
|
)
|