tweak proxy
This commit is contained in:
parent
303e52da3e
commit
3bd4feb0ed
@ -7,31 +7,24 @@ import { COOKIE_KEYS } from '../../lib/constants';
|
||||
const inProd = process.env.NODE_ENV === 'production';
|
||||
|
||||
const handler = (req: NextApiRequest, res: NextApiResponse) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// removes the api prefix from url
|
||||
// req.url = req.url!.replace(/^\/api/, '');
|
||||
|
||||
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 forwards the cookies to the target server
|
||||
// don't forward the cookies to the target server
|
||||
req.headers.cookie = '';
|
||||
|
||||
if (authorization) {
|
||||
req.headers.authorization = `Bearer ${authorization}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* if an error occurs in the proxy, we will reject the promise.
|
||||
* it is so important. if you don't reject the promise,
|
||||
* you're facing the stalled requests issue.
|
||||
*/
|
||||
proxy.once('error', reject);
|
||||
|
||||
proxy.web(req, res);
|
||||
proxy.web(req, res, undefined, (err) => {
|
||||
if (err) return reject(err);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user