MCPcopy
hub / github.com/vercel/next.js / initMiddleware

Function initMiddleware

test/integration/api-support/pages/api/cors.js:5–15  ·  view source on GitHub ↗
(middleware)

Source from the content-addressed store, hash-verified

3// Helper method to wait for a middleware to execute before continuing
4// And to throw an error when an error happens in a middleware
5function initMiddleware(middleware) {
6 return (req, res) =>
7 new Promise((resolve, reject) => {
8 middleware(req, res, (result) => {
9 if (result instanceof Error) {
10 return reject(result)
11 }
12 return resolve(result)
13 })
14 })
15}
16
17// Initialize the cors middleware
18const cors = initMiddleware(

Callers 1

cors.jsFile · 0.85

Calls 3

middlewareFunction · 0.50
rejectFunction · 0.50
resolveFunction · 0.50

Tested by

no test coverage detected