mercurius
mercurius copied to clipboard
Federation Gateway not work properly behind reverse proxy
I am testing mercurius as federation gateway, everything works correctly until i try to put it behind a proxy using caddy server.
This is my Caddyfile
:3000 {
reverse_proxy 127.0.0.1:8100
tls internal
}
This is the error i got
{
"statusCode": 500,
"code": "FST_ERR_BAD_STATUS_CODE",
"error": "Internal Server Error",
"message": "Called reply with an invalid status code: undefined"
}
{
errors: [
Error: Symbol(FEDERATED_ERROR)
at Object.sendRequest (LOCAL_PATH/node_modules/mercurius/lib/gateway/request.js:96:13)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async LOCAL_PATH/node_modules/mercurius/lib/gateway/make-resolver.js:498:24
at async Object.fastifyGraphQl [as graphql] (LOCAL_PATH/node_modules/mercurius/index.js:627:23) {
path: [Array],
locations: [Array],
extensions: [Object]
}
],
data: null
}
TypeError: Cannot read property 'data' of undefined
at maybeFormatErrors (LOCAL_PATH/node_modules/mercurius/index.js:644:39)
at Object.fastifyGraphQl [as graphql] (LOCAL_PATH/node_modules/mercurius/index.js:636:12)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Caddy Version: v2.4.6 node dependencies
{
"fastify": "^3.27.1",
"graphql": "^16.3.0",
"mercurius": "^9.3.2"
}
So i clone the mercurius master to do some debug. And found the cause, it was this code, ~~this request never reached the federated service when the original request comes from caddy proxy~~ the response is not a json
![image](https://user-images.githubusercontent.com/19581621/154621149-bd2c3268-2195-43c4-9ad2-8a415ccf5386.png)
The SDL query was ok
![image](https://user-images.githubusercontent.com/19581621/154621363-ce7500f1-3576-4b0e-89cf-2b5f414c6665.png)
I also try upgrade the udici
version to latest ^4.14.1
but, still the same
So the issue is the federated service return response in gzip, but the mercurius gateway can't handle it if the request comes from reverse proxy
We are not passing an Accept-Encoding header and it seems your server is always applying gzip encoding.
Could you try a quick fix passing Content-Encoding: identity
via initHeaders and rewriteHeaders.
It might also be that we need a fix somewhere to handle this. Could you write an example to reproduce this with Node.js?
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding
We are not passing an Accept-Encoding header and it seems your server is always applying gzip encoding.
Could you try a quick fix passing
Content-Encoding: identity
via initHeaders and rewriteHeaders.It might also be that we need a fix somewhere to handle this. Could you write an example to reproduce this with Node.js?
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding
The federated service is written in Go and unfortunately I am unable to replicate it outside the project. But my team decided to disable compression from the federated service.
@fahmifan is this issue solved?
@simoneb well, yeah we resolved it by remove the gzip compression from the federated service. And we enable gzip only in the Load balancer
I'm going to close this issue then