kylepaulsen / ValheimWebMap

A Valheim dedicated server mod to host a web accessible map.
29 stars 13 forks source link

SSL websocket and ws URL #3

Closed rysson closed 3 years ago

rysson commented 3 years ago

I have bug when I user a proxy, but this bug will be also occur on any https connection.

main.js:formatted:333 Mixed Content: The page at 'https:/valheim.server/map/' was loaded over HTTPS,
  but attempted to connect to the insecure WebSocket endpoint 'ws://valheim.server/'.
  This request has been blocked; this endpoint must be available over WSS.

There is missing SSL (wss) for https connections here https://github.com/kylepaulsen/ValheimWebMap/blob/eea559f341a263e2a0b20c499a4f3460ab1403d9/WebMap/web-src/websocket.js#L79

Next issue is about URL, because I use rewrite on my server, than map is available in /map/ preffix.

Is it possible add config option with websocket URL (to set schema and path)? And/or use X-Forwarded-Proto header (to force wss if https)?

kylepaulsen commented 3 years ago

Maybe I can just use the same host and path, but just change the protocol to wss or ws depending on https or http?

kylepaulsen commented 3 years ago

Hopefully this should be fixed now. v1.0.3 . Make sure to clear browser cache, as frontend code is aggressively cached.

rysson commented 3 years ago

Thanks!

replace(/^http/,"ws") – nice trick, I thought about it at night :-)

It resolves most cases, wws is OK. Second part of my issue is base-url, I don't how to forward mount point from my proxy. I have external haproxy on gateway (it removes https and set X-Forwarded-Proto), next nginx (on game machine, it rewrite /map) and your map mod.

Then if you use absolute paths like /map or /config it doesn't work on proxy rewrite. Css, js and icons are pointed relative and work. I suggest remove / from map and config.

I guess it will be works with 99% of cases. My 1% need to react on X-Forwarded-Proto (if available) instead of location scheme too (proxy – mod uses http, but browser – proxy uses https).

Thanks for you work.

rysson commented 3 years ago

A create micro pull request #5.

My 1% need to react on X-Forwarded-Proto

It seems that all work and do special code is needed for X-Forwarded-Proto.

kylepaulsen commented 3 years ago

Thanks, I'll let you know when this gets released.

kylepaulsen commented 3 years ago

This should be released now (v1.1.0). Hopefully it's fixed for you.

rysson commented 3 years ago

It works like a charm, thanks a lot!