Skip to content

Commit f113b00

Browse files
committed
chore: update http-proxy-middleware to version 4.1.1 and add tests for pathRewrite functionality
1 parent 4810909 commit f113b00

3 files changed

Lines changed: 43 additions & 6 deletions

File tree

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"connect-history-api-fallback": "^2.0.0",
6060
"express": "^5.2.1",
6161
"graceful-fs": "^4.2.11",
62-
"http-proxy-middleware": "^4.0.0",
62+
"http-proxy-middleware": "^4.1.1",
6363
"ipaddr.js": "^2.3.0",
6464
"launch-editor": "^2.13.2",
6565
"open": "^11.0.0",

test/server/proxy-option.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,29 @@ const proxyOptionPathsAsProperties = [
3333
pathRewrite: () => "/index.html",
3434
router: () => `http://localhost:${port3}`,
3535
},
36+
{
37+
context: "/send-data",
38+
target: `http://localhost:${port1}`,
39+
pathRewrite: (path, req, res) => {
40+
res.end("data sent from pathRewrite");
41+
42+
return path;
43+
},
44+
},
45+
{
46+
context: "/async-send-data",
47+
target: `http://localhost:${port1}`,
48+
pathRewrite: async (path, req, res) => {
49+
await new Promise((resolve) => {
50+
setTimeout(() => {
51+
res.end("async data sent from pathRewrite");
52+
resolve();
53+
}, 10);
54+
});
55+
56+
return path;
57+
},
58+
},
3659
];
3760

3861
const proxyOption = [
@@ -252,6 +275,20 @@ describe("proxy option", () => {
252275
expect(response.status).toBe(200);
253276
expect(response.text).toContain("Hello");
254277
});
278+
279+
it("should allow sending a response directly from pathRewrite", async () => {
280+
const response = await req.get("/send-data");
281+
282+
expect(response.status).toBe(200);
283+
expect(response.text).toBe("data sent from pathRewrite");
284+
});
285+
286+
it("should wait for an async pathRewrite that sends a response", async () => {
287+
const response = await req.get("/async-send-data");
288+
289+
expect(response.status).toBe(200);
290+
expect(response.text).toBe("async data sent from pathRewrite");
291+
});
255292
});
256293
});
257294

0 commit comments

Comments
 (0)