euchre-live

Euchre web-app for the socially distant family
git clone git://git.alexkarle.com/euchre-live.git
Log | Files | Refs | README | LICENSE

commit b058b34e881c4dacd3341266989ec05750624367 (patch)
parent db13059e9829237c4df4802f65fc71dbba5ec72e
Author: Alex Karle <alex@alexkarle.com>
Date:   Sun,  9 May 2021 00:21:23 -0400

frontend: Use websockets over TLS and https if connection secure

This is super exciting! I finally got around to configuring relayd(1)
(an OpenBSD base relay that I'm using to distribute load between
alexkarle.com and euchre.live) to do full TLS acceleration/termination
so that euchre.live can be run over HTTPS!

To handle this properly (without changing the dev workflow), the
frontend now needs to inspect the protocol and choose wss+https or
ws+http accordingly. This patch does just that.

Diffstat:
Massets/app.js | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/assets/app.js b/assets/app.js @@ -30,8 +30,13 @@ class App extends React.Component { tableList: [] }; const host = window.location.host; - socketAddr = 'ws://' + host + '/play'; - tablesAddr = 'http://' + host + '/tables'; + if (window.location.protocol === 'https:') { + socketAddr = 'wss://' + host + '/play'; + tablesAddr = 'https://' + host + '/tables'; + } else { + socketAddr = 'ws://' + host + '/play'; + tablesAddr = 'http://' + host + '/tables'; + } if (tableDebug) { client = new W3CWebSocket(socketAddr); client.onmessage = (event) => this.processResponse(event);