I have Nginx/openresty and some other services running on one VM. Basically VM accepts requests on Openresty and then openresty forwards requests to appropriate service. e.g. below requests getting forwarded to ServiceA, ServiceB and ServiceC respectively. It is working fine.
Now I need to expose a new endpoint which could get the responses from all services A, B and C. and then return one consolidated response.
I cannot use multiple proxy_pass in my location, could someone suggest how can I achieve that? e.g.
http://server:80/services/refALL --> returns a consolidated response from A, B and C Services.
you can do it like below. Basically you capture response from other services and then combine them
location /services/refALL {
content_by_lua_block {
local respA = ngx.location.capture("/services/refA")
local respB = ngx.location.capture("/services/refB")
local respC = ngx.location.capture("/services/refC")
ngx.say(respA.body .. respB.body .. respC.body)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With