koa-proxies
koa-proxies copied to clipboard
ctx refrence error
const querystring = require('querystring')
const proxy = require('koa-proxies')
module.exports = (app) => {
......
app.router.all(
`${config.prefix}/(.*)`,
proxy(`${config.prefix}/(.*)`, (params, ctx) => {
console.log('return options function call : ' + ctx.url)
return {
logs: true,
changeOrigin: true,
target: config.uasSvc,
events: {
proxyReq(proxyReq, req, res) {
console.log('proxy req event call: ' + ctx.url)
},
},
}
})
)
}
I fetch twice with different url, why the secondary proxyReq
function output is the FIRST fetch's url ?
output:
https://github.com/vagusX/koa-proxies/blob/15d3f1c8dc672150432fc6924c752b57230ad46a/index.js#L86-L96
in line 94, the first invocation of the event is cached here. If the method uses the 'ctx' passed from the previous options, the 'ctx' object inside it remains the same as the first time every time it is executed.