This repository has been archived on 2024-06-14. You can view files and clone it, but cannot push or open issues or pull requests.
icynet-admin/pages/api/[...path].ts
2022-09-20 17:58:49 +03:00

38 lines
910 B
TypeScript

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<void>((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,
},
};