From e89fefe335f1910286706ee117e4a85c09b98107 Mon Sep 17 00:00:00 2001 From: Peter C <12292660+PeterC89@users.noreply.github.com> Date: Wed, 17 Jan 2024 21:05:06 +0000 Subject: [PATCH 1/3] feat: Option to serve client on a different path --- README.md | 4 ++++ server/src/expressHandler.ts | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 644fec4d..53c8b016 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,10 @@ When running Sisyfos you can define the log level by setting the environment var - debug (info level plus: data send and received from Audiomixer) - trace (debug level plus: data send and received from Automation protocol) +### Serve client on a different path: + +When running Sisyfos you can change the root path from the default of `/` to another value by setting the environment variable `ROOT_PATH` + ### Open GUI in browser: ``` diff --git a/server/src/expressHandler.ts b/server/src/expressHandler.ts index 2dde4c22..9c8d9d1c 100644 --- a/server/src/expressHandler.ts +++ b/server/src/expressHandler.ts @@ -9,14 +9,15 @@ const app = express() const server = new Server(app) const socketServer = new SocketServer(server) const SERVER_PORT = 1176 +const ROOT_PATH = process.env.ROOT_PATH ?? '/' const staticPath = path.join( path.dirname(require.resolve('client/package.json')), 'dist' ) logger.data(staticPath).debug('Express static file path:') -app.use('/', express.static(staticPath)) +app.use(ROOT_PATH, express.static(staticPath)) server.listen(SERVER_PORT) -logger.info(`Server started at http://localhost:${SERVER_PORT}`) +logger.info(`Server started at http://localhost:${SERVER_PORT}/${ROOT_PATH}`) socketServer.on('connection', (socket: any) => { logger.info(`Client connected: ${socket.client.id}`) From cd5f44b2694040b8289e021fdc176219bd5442d4 Mon Sep 17 00:00:00 2001 From: Peter C <12292660+PeterC89@users.noreply.github.com> Date: Thu, 18 Jan 2024 00:35:32 +0000 Subject: [PATCH 2/3] fix: Use root path for socket.io server --- client/index.tsx | 7 ++++++- server/src/expressHandler.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/client/index.tsx b/client/index.tsx index b7d0face..bab4a487 100644 --- a/client/index.tsx +++ b/client/index.tsx @@ -44,7 +44,12 @@ const unsubscribe = window.storeRedux.subscribe(() => { window.reduxState = window.storeRedux.getState() }) -window.socketIoClient = io() +const { pathname } = window.location +const socketServerPath = + pathname + (pathname.endsWith('/') ? '' : '/') + 'socket.io/' +window.socketIoClient = io({ + path: socketServerPath, +}) window.socketIoClient.emit(SOCKET_GET_SNAPSHOT_LIST) window.socketIoClient.emit(SOCKET_GET_CCG_LIST) window.socketIoClient.emit(SOCKET_GET_MIXER_PRESET_LIST) diff --git a/server/src/expressHandler.ts b/server/src/expressHandler.ts index 9c8d9d1c..a6bc6955 100644 --- a/server/src/expressHandler.ts +++ b/server/src/expressHandler.ts @@ -5,11 +5,15 @@ import express from 'express' import path from 'path' import { Server } from 'http' import { Server as SocketServer } from 'socket.io' +const ROOT_PATH = process.env.ROOT_PATH ?? '/' +const SOCKET_SERVER_PATH = + ROOT_PATH + (ROOT_PATH.endsWith('/') ? '' : '/') + 'socket.io/' const app = express() const server = new Server(app) -const socketServer = new SocketServer(server) +const socketServer = new SocketServer(server, { + path: SOCKET_SERVER_PATH, +}) const SERVER_PORT = 1176 -const ROOT_PATH = process.env.ROOT_PATH ?? '/' const staticPath = path.join( path.dirname(require.resolve('client/package.json')), 'dist' From e4e75f2d15a78905ebd8c0f580d7bcca82ef7c92 Mon Sep 17 00:00:00 2001 From: Peter C <12292660+PeterC89@users.noreply.github.com> Date: Thu, 18 Jan 2024 12:16:16 +0000 Subject: [PATCH 3/3] docs: Fix Readme formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Anders Frederik Jørgensen --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 53c8b016..43d1e513 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,8 @@ When running Sisyfos you can define the log level by setting the environment var ### Serve client on a different path: -When running Sisyfos you can change the root path from the default of `/` to another value by setting the environment variable `ROOT_PATH` +When running Sisyfos you can change the root path from the default of `/` to another value by setting the environment variable `ROOT_PATH`. + ### Open GUI in browser: