express-http-proxy icon indicating copy to clipboard operation
express-http-proxy copied to clipboard

Proxy to google maps API not working

Open okezieokpara opened this issue 4 years ago • 1 comments

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. google-maps-error

This same request works well when I tried request/axios Am I doing anything wrong or this is just the wrong use case.

okezieokpara avatar Oct 02 '19 11:10 okezieokpara

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?

yaizudamashii avatar Oct 08 '19 19:10 yaizudamashii