Apollo server + subscriptions + websocket + redirects (reverse proxy issue)

I’m trying to deploy an apollo server to render.com with graphql subscriptions enabled. I have a local setup using docker/nginx with reverse proxies working: (server uses /graphql for both http and websocket)

// relevant part from the nginx.conf
location /graphql {
        proxy_pass  http://backend/graphql;
        proxy_set_header    Host                $http_host;
        proxy_set_header    X-Real-IP           $remote_addr;
        proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;

what would be the equivalent for a render.com “rewrite” ?
/graphql => https://my-backend-url.com/graphql won’t work

This post is migrated from slack, the discussion continued as bellow:

adrian 6 days ago

If I understand correctly, you have something like example.com which serves the frontend and you’d like to pass through example.com/graphql to backend.example.com/graphql?

gergo 5 days ago

Yes, exactly. This is a common pattern if you want to avoid CORS. (and your frontend and backend is in a different service)

gergo 5 days ago

One workaround for this is to use a dockerized service instead of a plain static site.

gergo 5 days ago

Also It would be nice to manage redirects and rewrites from code. sg like: https://docs.netlify.com/routing/redirects/#syntax-for-the-redirects-file


Redirects and rewrites

Netlify builds, deploys, and hosts your front end. Learn how to get started, see examples, and view documentation for the modern web platform. (16 kB)

adrian 5 days ago

@gergo what was the rewrite rule you tried? I think a /graphql -> https://…/graphql rule should work

gergo 4 days ago

@adrian unfortunately that doesn’t work

1 Like

+1 for this question

Having a general-purposed reverse proxy will empower the developers a lot. A Heroku equivalent could be https://github.com/funwhilelost/heroku-reverse-proxy. Considering render.com has public web service + private service, it is super helpful to add it to the public web service layer and connect it to services in the private layer.

@grego Sorry about the delay, we’re looking into it and will post an update as soon as we have more info.

Hello @grego,
I apologize for the extended delay, I made an example and have been trying to get a fix or workaround, but this feature will take some time. I have created an issue and submitted a feature request that you can upovte to get notified on status changes. https://feedback.render.com/features/p/support-websockets-in-static-site-rewrites