import { proxy } from '../../server/proxy'; import Cookies from 'cookies'; import { NextApiRequest, NextApiResponse } from 'next'; import { COOKIE_KEYS } from '../../lib/constants'; const inProd = process.env.NODE_ENV === 'production'; const handler = (req: NextApiRequest, res: NextApiResponse) => { return new Promise((resolve, reject) => { const cookies = new Cookies(req, res, { keys: COOKIE_KEYS, secure: inProd, }); const authorization = cookies.get('authorization', { signed: true }); // don't forward the cookies to the target server req.headers.cookie = ''; if (authorization) { req.headers.authorization = `Bearer ${authorization}`; } proxy.web(req, res, undefined, (err) => { if (err) return reject(err); resolve(); }); }); }; export default handler; export const config = { api: { bodyParser: false, }, };