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

Can't update path with proxyReqPathResolver

Open pr1ntr opened this issue 5 years ago • 2 comments

I am trying to do some app auth logic based on a condition and then replace the path and query if it succeeds. This seems to have no effect Here is my whole thing:

const express = require('express')
const proxy = require('express-http-proxy')
const fs = require('fs')
const https = require('https')
const app = express()
const { authHandler } = require('./backend/')


const handleAuthProxy = async (req) => {
  let headers = {}

  for ( let key in req.headers) {
    headers[key] = [
      {
        key,
        value: req.headers[key],
      },
    ]
  }


  const event = {
    Records: [
      {
        cf: {
          request: {
            uri: req.url,
            headers,
            origin: {
              protocol: 'https',
            },
          },

        },
      },
    ],

  }

  const { uri  } = await authHandler(event)

  return uri
}


app.get('/*', proxy('http://localhost:3000', {
  memoizeHost: false,
  proxyReqPathResolver: async (req) => {
    const { pathname } = req._parsedUrl
    if (pathname === '/results' && req.query.code) {
      const uri = await handleAuthProxy(req)
      return uri
    } else return req.url
  },
}))


https.createServer({
  key: fs.readFileSync('./cert/server.key'),
  cert: fs.readFileSync('./cert/server.cert'),
}, app).listen(8000, () => console.log('listening 8000'))

pr1ntr avatar Mar 16 '21 01:03 pr1ntr

Same here!

const userServiceProxy = httpProxy(SERVICE_ENDPOINTS.USERS_URL, {
    proxyReqPathResolver: req => req.url.replace('/private', '/')
});

proxyReqPathResolver is never called during execution

bleszerd avatar Apr 01 '22 14:04 bleszerd

this seems to still be broken, any updates?

denischiciudean avatar Nov 14 '22 15:11 denischiciudean