fix websocket over secure connection (#542)

* fix https connection

* explicity dependency

Former-commit-id: 0876deb1e9
This commit is contained in:
Hayden 2023-08-24 06:28:56 -08:00 committed by GitHub
parent 0b021e898f
commit 94e81d14fa
3 changed files with 10 additions and 1 deletions

View file

@ -13,7 +13,12 @@ let socket: WebSocket | null = null;
const listeners = new Map<ServerEvent, (() => void)[]>(); const listeners = new Map<ServerEvent, (() => void)[]>();
function connect(onmessage: (m: EventMessage) => void) { function connect(onmessage: (m: EventMessage) => void) {
const ws = new WebSocket(`ws://${window.location.host}/api/v1/ws/events`); let protocol = "ws";
if (window.location.protocol === "https:") {
protocol = "wss";
}
const ws = new WebSocket(`${protocol}://${window.location.host}/api/v1/ws/events`);
ws.onopen = () => { ws.onopen = () => {
console.debug("connected to server"); console.debug("connected to server");

View file

@ -48,6 +48,7 @@
"daisyui": "^2.24.0", "daisyui": "^2.24.0",
"dompurify": "^3.0.0", "dompurify": "^3.0.0",
"h3": "^1.7.1", "h3": "^1.7.1",
"http-proxy": "^1.18.1",
"markdown-it": "^13.0.1", "markdown-it": "^13.0.1",
"pinia": "^2.0.21", "pinia": "^2.0.21",
"postcss": "^8.4.16", "postcss": "^8.4.16",

View file

@ -47,6 +47,9 @@ dependencies:
h3: h3:
specifier: ^1.7.1 specifier: ^1.7.1
version: 1.7.1 version: 1.7.1
http-proxy:
specifier: ^1.18.1
version: 1.18.1
markdown-it: markdown-it:
specifier: ^13.0.1 specifier: ^13.0.1
version: 13.0.1 version: 13.0.1