udevbe / greenfield

HTML5 Wayland compositor :seedling:
GNU Affero General Public License v3.0
913 stars 28 forks source link

Reverse proxy support? #93

Closed m-bers closed 2 years ago

m-bers commented 2 years ago

I'm trying to put greenfield behind a reverse proxy (don't want to advertise both 8080 and 8081) but running into issues with the compositor-proxy URL in the demo module's index.ts.

Here's my NGINX config:

server {
   listen 80;
   location / {
      proxy_pass http://127.0.0.1:8080;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
   }
   location ~ ^/compositorProxy(.*)$ {
      proxy_http_version 1.1;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_pass http://127.0.0.1:8081/$1;
   }
}

Then in compositor-module/demo-compositor/index.ts:

...
  connect8081Button.onclick = () => {
    const compositorProxyURL = new URL('ws://localhost/compositorProxy')
    compositorProxyURL.searchParams.append('compositorSessionId', compositorSessionId)
    compositorProxyConnector.connectTo(compositorProxyURL)
  }
...

And I get this in the compositor proxy log:

{"level":50,"time":1646594472149,"pid":73,"hostname":"cae4075f6b94","name":"main","msg":"Bad or missing compositorSessionId query parameter."}
Zubnix commented 2 years ago

You can run the proxy on any port of your choosing if you don't want to use 8081: https://github.com/udevbe/greenfield/blob/master/compositor-proxy/src/config.yaml#L5

As for your error, did you specify a matching COMPOSITOR_SESSION_ID environment variable when running the proxy? https://github.com/udevbe/greenfield#greenfield-compositor-proxy

m-bers commented 2 years ago

You can run the proxy on any port of your choosing if you don't want to use 8081:

Yes, and it does work if I change the port to something else both in the docker-compose.yaml and in index.ts for the demo module, but I am trying to get BOTH the compositor module and the compositor proxy to listen on port 80, but with the module listening on / and the proxy URI rewritten to /compositorProxy

As for your error, did you specify a matching COMPOSITOR_SESSION_ID environment variable when running the proxy?

Yeah I'm just using the default COMPOSITOR_SESSION_ID: test123 in both the docker-compose.yaml and index.ts

Zubnix commented 2 years ago

What url is the reverse proxy using after rewrite? I know reverse proxy works as we have greenfield running on kubernetes behind an nginx ingress, so I suspect the rewrite rules might screw with the url params. The nginx logs should show this.

m-bers commented 2 years ago

I got it working, I apparently neglected the rewrite rule rewrite ^/compositorProxy(/.*)$ $1 break; though I could have sworn I put it in.

Here's what I did to get it working FWIW: https://github.com/m-bers/greenfield/commit/c504bd4b73ad3abfaeba96013e85bf1b99bcd791