forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware.js
47 lines (40 loc) · 1.3 KB
/
middleware.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { NextResponse } from 'next/server'
import { useCases, notUsingEval, usingEval } from './lib/utils'
import {
usingWebAssemblyCompile,
usingWebAssemblyInstantiate,
usingWebAssemblyInstantiateWithBuffer,
} from './lib/wasm'
export async function middleware(request) {
if (request.nextUrl.pathname === `/${useCases.eval}`) {
return new Response(null, {
headers: { data: JSON.stringify(await usingEval()) },
})
}
if (request.nextUrl.pathname === `/${useCases.noEval}`) {
return new Response(null, {
headers: { data: JSON.stringify(await notUsingEval()) },
})
}
if (request.nextUrl.pathname === `/${useCases.wasmCompile}`) {
return new Response(null, {
headers: { data: JSON.stringify(await usingWebAssemblyCompile(9)) },
})
}
if (request.nextUrl.pathname === `/${useCases.wasmInstanciate}`) {
return new Response(null, {
headers: { data: JSON.stringify(await usingWebAssemblyInstantiate(9)) },
})
}
if (request.nextUrl.pathname === `/${useCases.wasmBufferInstanciate}`) {
return new Response(null, {
headers: {
data: JSON.stringify(await usingWebAssemblyInstantiateWithBuffer(9)),
},
})
}
return NextResponse.next()
}
export const config = {
matcher: Object.values(useCases).map((route) => `/${route}`),
}