'Javascript `http-proxy-middleware` onProxyRes and onProxyReq signature parameters
I'm new to Javascript, and it's a mind bending world to me.
I have a [web app] that talks to a [proxy] that talks to a [web service].
In the signature, onProxyRes(proxyRes, req, res), where do each of the parameters originate? It seems like all documentation assumes you already know how it works.
So far, it seems obvious to me req was the original request, does this mean res is the original response? If I am trying to inject headers, should I be updating proxyRes?
I'm having a CORS error, I believe I just need to inject the header...
'Access-Control-Allow-Origin', '*'
Solution 1:[1]
https://www.npmjs.com/package/http-proxy-middleware indicates how to use this feature.
function onProxyRes(proxyRes, req, res) {
proxyRes.headers['Access-Control-Allow-Origin'] = '*';
}
should work. However, I haven't gotten my example to work yet, so I am hoping another reply will come in, or you have it figured out now.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Karl Henselin |
