Skip to content

Commit

Permalink
fix websocket over secure connection (#542)
Browse files Browse the repository at this point in the history
* fix https connection

* explicity dependency
  • Loading branch information
hay-kot committed Aug 24, 2023
1 parent 5438898 commit 0876deb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion frontend/composables/use-server-events.ts
Expand Up @@ -13,7 +13,12 @@ let socket: WebSocket | null = null;
const listeners = new Map<ServerEvent, (() => 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");
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0876deb

Please sign in to comment.