Files
next.js/test/production/standalone-mode/required-server-files/middleware-node.js
JJ KasperandGitHub cfc74ef891 Ensure node middleware is handled with standalone (#75765)
This makes sure we properly copy the necessary files in standalone mode
and node middleware is configured also adds regression test for this.
2025-02-06 23:16:02 +00:00

25 lines
565 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,
})
}
return NextResponse.next()
}