Learn to add response headers at the edge.
Below is the code from middleware.ts showing how to add response headers at the edge:
import { NextResponse } from 'next/server'export default function middleware() {// Store the response so we can modify its headersconst response = NextResponse.next()// Set custom headerresponse.headers.set('x-modified-edge', 'true')// Return responsereturn response}
https://edge-functions-add-header.vercel.app
You can choose from one of the following two methods to use this repository:
Deploy the example using Vercel:
Execute
pnpm create next-app --example https://github.com/vercel/examples/tree/main/edge-middleware/add-header add-header
Next, run Next.js in development mode:
pnpm dev
Deploy it to the cloud with Vercel (Documentation).
Learn to add response headers at the edge.
Below is the code from middleware.ts showing how to add response headers at the edge:
import { NextResponse } from 'next/server'export default function middleware() {// Store the response so we can modify its headersconst response = NextResponse.next()// Set custom headerresponse.headers.set('x-modified-edge', 'true')// Return responsereturn response}
https://edge-functions-add-header.vercel.app
You can choose from one of the following two methods to use this repository:
Deploy the example using Vercel:
Execute
pnpm create next-app --example https://github.com/vercel/examples/tree/main/edge-middleware/add-header add-header
Next, run Next.js in development mode:
pnpm dev
Deploy it to the cloud with Vercel (Documentation).