manifold/web/lib/api/cors.ts
Marshall Polaris 3987baa11b
Add Vercel routes for public write API (#280)
* Improve typing of client CORS helper

* Take node-fetch as a dependency

* Add explicit Firebase region into config

* Add new Vercel proxy API routes that talk to backend

* Call Vercel proxy routes from `api-call` module

* Tweak import to try to get Vercel happy

* Tidy up a tiny bit
2022-05-23 14:16:56 -07:00

21 lines
534 B
TypeScript

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