-
Notifications
You must be signed in to change notification settings - Fork 852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handler types are incorrectly coupled to express.js #719
Comments
Hi, thanks for the report. I'm aware of this issue. Looking at ways to improve typing so For now you could try type the middleware with const apiProxy = createProxyMiddleware(apiProxyOptions) as any; (Similar issue with nextjs: #713 (comment)) |
Will you get the same issue for express? Express types extend the base node types. In the ref’d issue, I observed ClientRequest, not IncomingMessage. Nextjs also uses the basic node primitives—the next issue is disjoint, but related. I’m willing to attempt a patch with verification of compat between server libs if you’re open to reviewing it |
Express users will loose express specific request and response properties when node primitives are used. This would mean regression for express users. Happy to see a good solution which'll work for different servers. |
Using TypeScript Generics with default values might be a solution. http-proxy-middleware/src/types.ts Lines 17 to 19 in 6b5d7a8
Default values for If you need extend |
Fixed in #730 Removal of |
Checks
http-proxy-middleware
.Describe the bug (be clear and concise)
TS compilation error occurs with compatible response & reply primitives.
I expect a type signature from
createProxyMiddleware
to yield:(req: IncomingMessage, res: http.ServerResponse, next?: ...) => void
. However, the returned handler is explicitly coupled to express:(req: expresscore.Request, res: expresscore.Response)
, etc.This is invalid.
When my server tries to then:
i get a compilation error, because i'm using raw node interfaces (legit works!), but createProxyMiddleware demands express.js handlers.
Step-by-step reproduction instructions
Expected behavior (be clear and concise)
No compilation error
How is http-proxy-middleware used in your project?
What http-proxy-middleware configuration are you using?
What OS/version and node/version are you seeing the problem?
Additional context (optional)
n/a
The text was updated successfully, but these errors were encountered: