mirror of
https://github.com/ruisaraiva19/favycon.git
synced 2026-09-12 19:51:07 +05:00
15 lines
456 B
TypeScript
15 lines
456 B
TypeScript
import { NextApiRequest, NextApiResponse } from 'next'
|
|
|
|
// Helper method to wait for a middleware to execute before continuing
|
|
// And to throw an error when an error happens in a middleware
|
|
export const runMiddleware = (req: NextApiRequest, res: NextApiResponse, fn: any) => {
|
|
return new Promise((resolve, reject) => {
|
|
fn(req, res, (result: any) => {
|
|
if (result instanceof Error) {
|
|
return reject(result)
|
|
}
|
|
return resolve(result)
|
|
})
|
|
})
|
|
}
|