manifold/web/lib/api/cors.ts
Marshall Polaris 731e5d5b7c
Apply permissive CORS headers to API (#115)
* Take cors package as dependency

* Apply permissive CORS headers to all API routes
2022-04-30 13:30:49 -07:00

21 lines
524 B
TypeScript

import Cors from 'cors'
import { NextApiRequest, NextApiResponse } from 'next'
export function applyCorsHeaders(
req: NextApiRequest,
res: NextApiResponse,
params: object
) {
// 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 = {}