express-http-proxy
express-http-proxy copied to clipboard
Can't update path with proxyReqPathResolver
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'))
Same here!
const userServiceProxy = httpProxy(SERVICE_ENDPOINTS.USERS_URL, {
proxyReqPathResolver: req => req.url.replace('/private', '/')
});
proxyReqPathResolver is never called during execution
this seems to still be broken, any updates?