express-http-proxy
express-http-proxy copied to clipboard
Proxy to google maps API not working
Hello, I am trying this library for proxying to google maps api. This is my setup:
router.get('/api/google', (req, res, next) => proxy('https://maps.googleapis.com', { proxyReqPathResolver: (req) => 'maps/api/geocode/json?key=${GOOGLE_MAP_KEY}&latlng=6.42533,+3.4148205064377684&language=en-GB', proxyReqOptDecorator: (proxyReqOpts, srcReq) => { proxyReqOpts.headers['x-forwarded-for'] = '' proxyReqOpts.headers.cookie = '' return proxyReqOpts }, })(req, res, next))
But every time, google maps returns: Your client has issued a malformed or illegal request. That’s all we know.
This same request works well when I tried request/axios Am I doing anything wrong or this is just the wrong use case.
Yeah Google doesn't seem to work.
I've tried
app.use('/google', proxy('https://www.google.com', { preserveHostHdr: true }));
which yields bad certificate crash,
I've also tried
app.use('/google', proxy('https://www.google.com',
{
preserveHostHdr: true,
proxyReqOptDecorator: function(proxyReqOpts, originalReq) {
proxyReqOpts.rejectUnauthorized = false;
return proxyReqOpts;
}
}));
to ignore the certificate, but then I get the same error as you got.
Has someone figured this out?