I'm supposed to get the request via proxy
I'm getting ALTNAME error
function relayRequestHeaders(proxyReq, req) {
Object.keys(req.headers).forEach(function (key) {
proxyReq.setHeader(key, req.headers[key]);
});
};
function relayResponseHeaders(proxyRes, req, res) {
Object.keys(proxyRes.headers).forEach(function (key) {
res.append(key, proxyRes.headers[key]);
});
};
const options = {
target: 'example.com',
logLevel: 'debug',
onProxyReq: relayRequestHeaders,
onProxyRes: relayResponseHeaders
}
var app = express();
app.use('/apps', proxy(options));
app.listen(3000);
When ever I add changeOrigin: true I get 404 errors. Any help?
@coderpradp Did you ever figure this out?
Getting same error when proxying request to a ssl based server
Had same issue.
Added changeOrigin to fix this and pathRewrite to fix 404
const apiProxy = proxy('/api', {
target: API_ENDPOINT,
changeOrigin: true,
pathRewrite: { '^/api': '' }, // remove leading /api to match real API urls
})
What location is this file found at?
I have already set changeOrigin to true.
I think that the error came from a self signed certificate.
then:
how to accept SELF SIGNED certificate in dev environment?
I have already set
changeOriginto true.
I think that the error came from a _self signed_ certificate.
then:
how to accept SELF SIGNED certificate in dev environment?
it seems to be enough to set secure: false
A test https server I was trying to proxy to was using a self signed certificate, I found that by striping all the request headers seemed to allow it to successfully connect and return a response.
I changed the relayRequestHeaders function to this;
function relayRequestHeaders(proxyReq, req) {
Object.keys(req.headers).forEach(function (key) {
// strip all the request headers, as the receiving server is freaking out on one of them
proxyReq.setHeader(key, '');
});
}
Most helpful comment
Had same issue.
Added
changeOriginto fix this andpathRewriteto fix 404