2022-04-30 20:30:49 +00:00
|
|
|
import Cors from 'cors'
|
|
|
|
import { NextApiRequest, NextApiResponse } from 'next'
|
|
|
|
|
|
|
|
export function applyCorsHeaders(
|
|
|
|
req: NextApiRequest,
|
|
|
|
res: NextApiResponse,
|
2022-05-23 21:16:56 +00:00
|
|
|
params: Cors.CorsOptions
|
2022-04-30 20:30:49 +00:00
|
|
|
) {
|
|
|
|
// This cors module is made as express.js middleware, so it's easier to promisify it for ourselves.
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
Cors(params)(req, res, (result) => {
|
|
|
|
if (result instanceof Error) {
|
|
|
|
return reject(result)
|
|
|
|
}
|
|
|
|
return resolve(result)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const CORS_UNRESTRICTED = {}
|