feat: support function-based dynamic target for ServerOptions#56
feat: support function-based dynamic target for ServerOptions#56tbontb-iaq wants to merge 2 commits into
Conversation
Allow `target` option to accept a function `(req) => ProxyTarget` in addition to a static `ProxyTarget`, enabling per-request dynamic routing. The function is resolved in createRightProxy before any passes run, so all downstream code sees a resolved static target. 🤖 This code was written by AI (OpenCode / DeepSeek v4 Pro).
|
Wow, that's a good idea, I think. Code looks good. |
|
Further feedback: Tests include a placeholder-ish override test, there is no websocket coverage even though the change affects ws too, and a throwing target function currently looks like it would escape instead of going through proxy error handling. Can you clean this up a bit? |
…up tests Address review feedback: - Wrap function target call in try-catch to emit errors properly - Add websocket dynamic target test coverage - Remove placeholder-like per-request override test - Add test for target function throwing an error 🤖 Code written by AI (OpenCode / DeepSeek v4 Pro).
|
Thanks for the review! I've addressed all three points in b0063bf:
All 310 tests pass, no regressions. |
|
Thanks! |
|
Is there any progress? |
Allow
targetoption to accept a function(req) => ProxyTargetin addition to a staticProxyTarget, enabling per-request dynamic routing.Changes
lib/http-proxy/index.ts: AddedProxyTargetFunctiontype, changedServerOptions.targetto acceptProxyTarget | ProxyTargetFunction. Function target is resolved increateRightProxybefore any passes run, so all downstream code sees a resolved static target.lib/index.ts: ExportedProxyTargetFunctiontype.lib/test/http/dynamic-target.test.ts: 6 new tests covering path-based routing,{port, host}object return, and per-request override.Example
🤖 This code was written by AI (OpenCode / DeepSeek v4 Pro).