diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2024-06-12 17:03:11 +0100 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2024-06-12 17:03:11 +0100 |
commit | 751e81923198c9e0a840540ff7f2d2d205f3500e (patch) | |
tree | bbf2764a02690d1f77925905dc5d0c67ac865171 /src/server-component.mjs | |
parent | 23506897a2a0862a3563a0c24894a20c962167ad (diff) | |
download | lustre-751e81923198c9e0a840540ff7f2d2d205f3500e.tar.gz lustre-751e81923198c9e0a840540ff7f2d2d205f3500e.zip |
:recycle: Use wss protocol if page is served over https.
Diffstat (limited to 'src/server-component.mjs')
-rw-r--r-- | src/server-component.mjs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/server-component.mjs b/src/server-component.mjs index ab08801..0700939 100644 --- a/src/server-component.mjs +++ b/src/server-component.mjs @@ -60,9 +60,12 @@ export class LustreServerComponent extends HTMLElement { } else if (prev !== next) { const id = this.getAttribute("id"); const route = next + (id ? `?id=${id}` : ""); + const protocol = window.location.protocol === "https:" ? "wss" : "ws"; this.#socket?.close(); - this.#socket = new WebSocket(`ws://${window.location.host}${route}`); + this.#socket = new WebSocket( + `${protocol}://${window.location.host}${route}`, + ); this.#socket.addEventListener("message", (message) => this.messageReceivedCallback(message), ); |