Files
647d923a3f Cherry-pick ghsa commits to canary (#93614)
## What?

Includes the changes from 16-2.

---------

Co-authored-by: JJ Kasper <[email protected]>
Co-authored-by: Josh Story <[email protected]>
Co-authored-by: Zack Tanner <[email protected]>
Co-authored-by: Benjamin Woodruff <[email protected]>
2026-05-07 21:57:46 +00:00

28 lines
682 B
JavaScript

import { NextResponse } from 'next/server'
import { ImageResponse } from 'next/og'
import fs from 'fs'
import path from 'path'
export const config = {
runtime: 'nodejs',
}
export async function middleware(req) {
console.log('middleware', req.url)
console.log(
'env',
await fs.promises.readFile(path.join(process.cwd(), '.env'))
)
if (req.nextUrl.pathname === '/a-non-existent-page/to-test-with-middleware') {
return new ImageResponse(<div>Hello world</div>, {
width: 1200,
height: 600,
})
}
if (req.nextUrl.pathname === '/dynamic/secret') {
return new NextResponse('Unauthorized', { status: 401 })
}
return NextResponse.next()
}