From 0876deb1e9c341550f7e29a809b07b15d1462042 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Thu, 24 Aug 2023 06:28:56 -0800 Subject: [PATCH] fix websocket over secure connection (#542) * fix https connection * explicity dependency --- frontend/composables/use-server-events.ts | 7 ++++++- frontend/package.json | 1 + frontend/pnpm-lock.yaml | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/composables/use-server-events.ts b/frontend/composables/use-server-events.ts index 2d4eaa0..53f0631 100644 --- a/frontend/composables/use-server-events.ts +++ b/frontend/composables/use-server-events.ts @@ -13,7 +13,12 @@ let socket: WebSocket | null = null; const listeners = new Map 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 = () => { console.debug("connected to server"); diff --git a/frontend/package.json b/frontend/package.json index 1785612..db24cb8 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -48,6 +48,7 @@ "daisyui": "^2.24.0", "dompurify": "^3.0.0", "h3": "^1.7.1", + "http-proxy": "^1.18.1", "markdown-it": "^13.0.1", "pinia": "^2.0.21", "postcss": "^8.4.16", diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml index 4d4e37c..a8e1be3 100644 --- a/frontend/pnpm-lock.yaml +++ b/frontend/pnpm-lock.yaml @@ -47,6 +47,9 @@ dependencies: h3: specifier: ^1.7.1 version: 1.7.1 + http-proxy: + specifier: ^1.18.1 + version: 1.18.1 markdown-it: specifier: ^13.0.1 version: 13.0.1