mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
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
10 lines
225 B
TypeScript
10 lines
225 B
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
export const GET = (req: NextRequest) => {
|
|
const url = new URL(req.url)
|
|
return NextResponse.json({
|
|
url: url.pathname,
|
|
nextUrl: req.nextUrl.pathname,
|
|
})
|
|
}
|