Files
next.js/test/integration/edge-runtime-dynamic-code/middleware.js
Niklas MischkulnigandGitHub 7861621f58 test: Refactor edge-runtime-dynamic-code test (#83390)
This test is about `eval`
But it also used a non-static middleware `matchers` config, which is going to break once we are more strict about this and throw a build error.
2025-09-03 23:22:16 +02:00

56 lines
1.4 KiB
JavaScript

import { NextResponse } from 'next/server'
import { notUsingEval, usingEval } from './lib/utils'
import {
usingWebAssemblyCompile,
usingWebAssemblyInstantiate,
usingWebAssemblyInstantiateWithBuffer,
} from './lib/wasm'
export async function middleware(request) {
if (request.nextUrl.pathname === '/using-eval') {
return new Response(null, {
headers: { data: JSON.stringify(await usingEval()) },
})
}
if (request.nextUrl.pathname === '/not-using-eval') {
return new Response(null, {
headers: { data: JSON.stringify(await notUsingEval()) },
})
}
if (request.nextUrl.pathname === '/using-webassembly-compile') {
return new Response(null, {
headers: { data: JSON.stringify(await usingWebAssemblyCompile(9)) },
})
}
if (request.nextUrl.pathname === '/using-webassembly-instantiate') {
return new Response(null, {
headers: { data: JSON.stringify(await usingWebAssemblyInstantiate(9)) },
})
}
if (
request.nextUrl.pathname === '/using-webassembly-instantiate-with-buffer'
) {
return new Response(null, {
headers: {
data: JSON.stringify(await usingWebAssemblyInstantiateWithBuffer(9)),
},
})
}
return NextResponse.next()
}
export const config = {
matcher: [
'/using-eval',
'/not-using-eval',
'/using-webassembly-compile',
'/using-webassembly-instantiate',
'/using-webassembly-instantiate-with-buffer',
],
}