Skip to content

Commit f901a2d

Browse files
authored
when post, put with json body, it is not working, so fix it (#3)
1 parent b3355b3 commit f901a2d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,16 @@ const httpProxyMiddleware = async (
4444
if (pathRewrite) {
4545
req.url = rewritePath(req.url as string, pathRewrite);
4646
}
47+
if(["POST", "PUT"].indexOf(req.method as string) >= 0 && typeof req.body === "object"){
48+
req.body = JSON.stringify(req.body);
49+
}
4750
proxy
51+
.once("proxyReq", ((proxyReq: any, req: any): void => {
52+
if(["POST", "PUT"].indexOf(req.method as string) >= 0 && typeof req.body === "string"){
53+
proxyReq.write(req.body);
54+
proxyReq.end();
55+
}
56+
}) as any)
4857
.once("proxyRes", resolve)
4958
.once("error", reject)
5059
.web(req, res, {

0 commit comments

Comments
 (0)