Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't update path with proxyReqPathResolver #480

Open
pr1ntr opened this issue Mar 16, 2021 · 2 comments
Open

Can't update path with proxyReqPathResolver #480

pr1ntr opened this issue Mar 16, 2021 · 2 comments

Comments

@pr1ntr
Copy link

pr1ntr commented Mar 16, 2021

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'))
@bleszerd
Copy link

bleszerd commented Apr 1, 2022

Same here!

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

proxyReqPathResolver is never called during execution

@denischiciudean
Copy link

this seems to still be broken, any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants