fixes http headers being set in wrong order

This commit is contained in:
nai-degen 2023-04-08 10:13:00 -05:00 committed by nai-degen
parent 45451c4486
commit c74c527f46
1 changed files with 7 additions and 8 deletions

View File

@ -22,16 +22,15 @@ const rewriteRequest = (proxyReq: http.ClientRequest, req: Request) => {
proxyReq.setHeader("Authorization", `Bearer ${key.key}`); proxyReq.setHeader("Authorization", `Bearer ${key.key}`);
if (req.method === "POST" && req.body) { if (req.method === "POST" && req.body) {
// body-parser and http-proxy-middleware don't play nice together
fixRequestBody(proxyReq, req);
}
if (req.body?.stream) { if (req.body?.stream) {
req.body.stream = false; req.body.stream = false;
const updatedBody = JSON.stringify(req.body); const updatedBody = JSON.stringify(req.body);
proxyReq.setHeader("Content-Length", Buffer.byteLength(updatedBody)); proxyReq.setHeader("Content-Length", Buffer.byteLength(updatedBody));
proxyReq.write(updatedBody); (req as any).rawBody = Buffer.from(updatedBody);
proxyReq.end(); }
// body-parser and http-proxy-middleware don't play nice together
fixRequestBody(proxyReq, req);
} }
}; };