From 056c02c5a520191fa8cbed6319abb3fded17729c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Thu, 26 Sep 2024 21:10:56 +0200 Subject: [PATCH] gets and uses forwarded prefix in socket.ts --- frontend/src/socket.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/frontend/src/socket.ts b/frontend/src/socket.ts index 8874903..9c5495a 100644 --- a/frontend/src/socket.ts +++ b/frontend/src/socket.ts @@ -6,10 +6,20 @@ export const hostname = process.env.NODE_ENV === "development" ? `localhost` : window.location.hostname; export const port = process.env.NODE_ENV === "development" ? 8001 : window.location.port; +// Get the forwarded prefix from the global variable +export const forwardedPrefix: string = + (window as any) /* eslint-disable-line @typescript-eslint/no-explicit-any */ + .__FORWARDED_PREFIX__ || ""; + +export const authority = `${hostname}:${port}${forwardedPrefix}`; + const URL = `ws://${hostname}:${port}/`; console.debug("Websocket: ", URL); -export const socket = io(URL, { path: "/ws/socket.io", transports: ["websocket"] }); +export const socket = io(URL, { + path: `${forwardedPrefix}/ws/socket.io`, + transports: ["websocket"], +}); export const updateValue = ( serializedObject: SerializedObject,