From ae4363f6f66c2557e0d521b15c0d8aff9fc16549 Mon Sep 17 00:00:00 2001 From: cv <34649812+cpvalente@users.noreply.github.com> Date: Fri, 4 Jun 2021 12:15:31 +0200 Subject: [PATCH] separe init processes separate processes to initialise: - express server - osc server - osc client --- server/main.js | 12 ++++++--- server/src/app.js | 54 +++++++++++++++++++++++++------------ server/src/config/config.js | 1 + 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/server/main.js b/server/main.js index 61795c8c0..32d7920cc 100644 --- a/server/main.js +++ b/server/main.js @@ -15,9 +15,15 @@ const { Notification } = require('electron'); const env = process.env.NODE_ENV || 'prod'; (async () => { - const { nodeapp } = import( + const { startServer, startOSCServer, startOSCClient } = await import( path.join('file:///', __dirname, env == 'prod' ? '../' : '', 'src/app.js') ); + // Start express server + startServer(); + // Start OSC Server (API) + startOSCServer(); + // Start OSC Client (Feedback) + startOSCClient(); })(); // Load Icons @@ -62,7 +68,7 @@ function createWindow() { win = new BrowserWindow({ width: 1920, - height: 1080, + height: 1000, minWidth: 500, minHeight: 530, maxWidth: 1920, @@ -199,7 +205,7 @@ ipcMain.on('set-window', (event, arg) => { if (arg === 'to-max') { // window full - win.setContentSize(1920, 1080); + win.setContentSize(1920, 1000); win.setPosition(0, 0); } else if (arg === 'to-tray') { // window to tray diff --git a/server/src/app.js b/server/src/app.js index abe8ec960..6c604b2d2 100644 --- a/server/src/app.js +++ b/server/src/app.js @@ -10,7 +10,7 @@ import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -var env = process.env.NODE_ENV || 'prod'; +const env = process.env.NODE_ENV || 'prod'; const file = join(__dirname, 'data/', config.database.filename); const adapter = new JSONFile(file); @@ -41,9 +41,6 @@ import { router as eventsRouter } from './routes/eventsRouter.js'; import { router as eventRouter } from './routes/eventRouter.js'; import { router as ontimeRouter } from './routes/ontimeRouter.js'; -// Setup default port -const port = process.env.PORT || config.server.port; - // Global Objects import { EventTimer } from './classes/EventTimer.js'; @@ -68,10 +65,22 @@ app.use('/event', eventRouter); app.use('/ontime', ontimeRouter); // serve react -app.use(express.static(path.join(__dirname, env == 'prod' ? '../' : '../../', 'client/build'))); +app.use( + express.static( + path.join(__dirname, env == 'prod' ? '../' : '../../', 'client/build') + ) +); app.get('*', (req, res) => { - res.sendFile(path.resolve(__dirname, env == 'prod' ? '../' : '../../', 'client', 'build', 'index.html')); + res.sendFile( + path.resolve( + __dirname, + env == 'prod' ? '../' : '../../', + 'client', + 'build', + 'index.html' + ) + ); }); // Implement route for errors @@ -82,20 +91,31 @@ app.use((err, req, res, next) => { // create HTTP server const server = http.createServer(app); -// init timer -global.timer = new EventTimer(server, config); -global.timer.setupWithEventList(data.events); +export const startServer = (overrideConfig = null) => { + // Setup default port + const serverPort = overrideConfig?.port || config.server.port; -// Start server -server.listen(port, '0.0.0.0', () => - console.log(`HTTP Server is listening on port ${port}`) -); + // Start server + server.listen(serverPort, '0.0.0.0', () => + console.log(`HTTP Server is listening on port ${serverPort}`) + ); + + // init timer + global.timer = new EventTimer(server, config); + global.timer.setupWithEventList(data.events); +}; // Start OSC server import { initiateOSC } from './controllers/OscController.js'; -initiateOSC(config.osc); +export const startOSCServer = (overrideConfig = null) => { + // Setup default port + const oscInPort = overrideConfig?.port || config.osc.port; + initiateOSC(config.osc); +}; -export function init() { - console.log('init'); -} +export const startOSCClient = (overrideConfig = null) => { + // Setup default port + const oscOutPort = overrideConfig?.port || config.osc.portOut; + console.log('initialise OSC Client at port: ', oscOutPort); +}; diff --git a/server/src/config/config.js b/server/src/config/config.js index 64ef4ef2b..f3d0ead85 100644 --- a/server/src/config/config.js +++ b/server/src/config/config.js @@ -11,5 +11,6 @@ export const config = { }, osc: { port: 8888, + portOut: 8889, }, };