Open brian428 opened 6 years ago
Please try to find the last version that this worked, between v2.0.4 (current) and v1.7.1.
Actually, it looks like it worked as recently as Karma 2.0.0. Not sure if that helps or not, since the commit I found (above) to /middleware/proxy.js was very recent. Could something else have changed between 2.0.0 and 2.0.2 that might have caused this?
We've been doing quite a lot of refactoring and sometimes tests don't cover every case. So yes ;-)
Expected behaviour
If a
proxyReq
function is set, it should run for all requests, not just requests that match paths defined inproxies
config object.Actual behaviour
This worked as expected (
proxyReq
always ran, if defined) prior to upgrading to Angular 6 / Angular CLI 6. Now,proxyReq
only seems to run if one or more paths are set inproxies
, and only runs for paths that match those defined inproxies
. I'm not sure when this changed (2.0?), or if it is actually related to the version ofnode-http-proxy
being used. (Edit: I'm on 2.0.2, so I don't think this change could be the culprit, but just in case: https://github.com/karma-runner/karma/commit/0dc8ea4ab5d281e62d324ab02bc79acd1bdd38b1#diff-a043d5a6a7b3405edd843f08f24e3da1)Environment Details
karma --version
): 2.0.2karma.config.js
fileSteps to reproduce the behaviour
proxyReq
function in the Karma config, but define noproxies
.proxyReq
function never runsproxies
that will not be used during your Karma runproxyReq
is still not calledproxies
that will be used during your Karma runproxyReq
is now calledJustification
Our app conditionally uses a set of mock JSON files to simulate a back-end server (based on runtime configuration). We find this very useful, for many reasons:
All that leads to a simple issue: many app server calls are not GET requests, and non-GET requests will fail when the target is a static JSON file. We use the
proxyReq
to change the request method from POST/PUT/DELETE to GET, so the calls can proceed without issue.Once I figured out that a
proxies
entry was required, I tried simply doing this to get theproxyReq
to run:But this just triggers an infinite loop in the handling of the request. The only alternative is to use a placeholder path for the mock JSON URLs, and use
proxyReq
to rewrite the path in addition to changing the request method.Ideally,
proxyReq
would run whether anyproxies
are defined or not. Or, in lieu of that, provide some way for a path inproxies
to triggerproxyReq
, while indicating that the target for the proxy path should just remain the same as the original path and without triggering an infinite loop.