Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"connect-history-api-fallback": "^2.0.0",
"express": "^5.2.1",
"graceful-fs": "^4.2.11",
"http-proxy-middleware": "^4.0.0",
"http-proxy-middleware": "^4.1.1",
"ipaddr.js": "^2.3.0",
"launch-editor": "^2.13.2",
"open": "^11.0.0",
Expand Down
37 changes: 37 additions & 0 deletions test/server/proxy-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ const proxyOptionPathsAsProperties = [
pathRewrite: () => "/index.html",
router: () => `http://localhost:${port3}`,
},
{
context: "/send-data",
target: `http://localhost:${port1}`,
pathRewrite: (path, req, res) => {
res.end("data sent from pathRewrite");

return path;
},
},
{
context: "/async-send-data",
target: `http://localhost:${port1}`,
pathRewrite: async (path, req, res) => {
await new Promise((resolve) => {
setTimeout(() => {
res.end("async data sent from pathRewrite");
resolve();
}, 10);
});

return path;
},
},
];

const proxyOption = [
Expand Down Expand Up @@ -252,6 +275,20 @@ describe("proxy option", () => {
expect(response.status).toBe(200);
expect(response.text).toContain("Hello");
});

it("should allow sending a response directly from pathRewrite", async () => {
const response = await req.get("/send-data");

expect(response.status).toBe(200);
expect(response.text).toBe("data sent from pathRewrite");
});

it("should wait for an async pathRewrite that sends a response", async () => {
const response = await req.get("/async-send-data");

expect(response.status).toBe(200);
expect(response.text).toBe("async data sent from pathRewrite");
});
});
});

Expand Down
Loading