File tree Expand file tree Collapse file tree 5 files changed +72
-0
lines changed
tests/fixtures/middleware-node-unsupported-cpp-addons Expand file tree Collapse file tree 5 files changed +72
-0
lines changed Original file line number Diff line number Diff line change 1+ export const metadata = {
2+ title : 'Simple Next App' ,
3+ description : 'Description for Simple Next App' ,
4+ }
5+
6+ export default function RootLayout ( { children } ) {
7+ return (
8+ < html lang = "en" >
9+ < body > { children } </ body >
10+ </ html >
11+ )
12+ }
Original file line number Diff line number Diff line change 1+ export default function Home ( ) {
2+ return (
3+ < main >
4+ < h1 > Home</ h1 >
5+ </ main >
6+ )
7+ }
Original file line number Diff line number Diff line change 1+ // bcrypt is using C++ Addons (.node binaries) which are unsupported currently
2+ // example copied from https://nextjs.org/blog/next-15-2#nodejs-middleware-experimental
3+ import bcrypt from 'bcrypt'
4+
5+ const API_KEY_HASH = process . env . API_KEY_HASH // Pre-hashed API key in env
6+
7+ export default async function middleware ( req ) {
8+ const apiKey = req . headers . get ( 'x-api-key' )
9+
10+ if ( ! apiKey || ! ( await bcrypt . compare ( apiKey , API_KEY_HASH ) ) ) {
11+ return new Response ( 'Forbidden' , { status : 403 } )
12+ }
13+
14+ console . log ( 'API key validated' )
15+ }
16+
17+ export const config = {
18+ runtime : 'nodejs' ,
19+ }
Original file line number Diff line number Diff line change 1+ /** @type {import('next').NextConfig } */
2+ const nextConfig = {
3+ output : 'standalone' ,
4+ eslint : {
5+ ignoreDuringBuilds : true ,
6+ } ,
7+ experimental : {
8+ nodeMiddleware : true ,
9+ } ,
10+ outputFileTracingRoot : __dirname ,
11+ }
12+
13+ module . exports = nextConfig
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " middleware-node-unsupported-cpp-addons" ,
3+ "version" : " 0.1.0" ,
4+ "private" : true ,
5+ "scripts" : {
6+ "postinstall" : " next build" ,
7+ "dev" : " next dev" ,
8+ "build" : " next build"
9+ },
10+ "dependencies" : {
11+ "bcrypt" : " ^6.0.0" ,
12+ "next" : " latest" ,
13+ "react" : " 18.2.0" ,
14+ "react-dom" : " 18.2.0"
15+ },
16+ "test" : {
17+ "dependencies" : {
18+ "next" : " >=15.2.0"
19+ }
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments