mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-05 06:19:11 +00:00
feat: start services from config
ability to override default ports and whatnot. as of now, it would need a server restart
This commit is contained in:
+5
-2
@@ -116,8 +116,11 @@
|
|||||||
"settings": {
|
"settings": {
|
||||||
"app": "ontime",
|
"app": "ontime",
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"osc_enabled": false,
|
"serverPort": 4001,
|
||||||
"osc_port": 8888,
|
"oscInPort": 8888,
|
||||||
|
"oscOutPort": 9999,
|
||||||
|
"oscOutIP": "127.0.0.1",
|
||||||
|
"oscEnabled": true,
|
||||||
"lock": false
|
"lock": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+31
-8
@@ -4,6 +4,7 @@ import { sessionId, user } from './utils/analytics.js';
|
|||||||
user.screenview('Node service', 'ontime').send();
|
user.screenview('Node service', 'ontime').send();
|
||||||
user.event('NODE', 'started', 'starting node service').send();
|
user.event('NODE', 'started', 'starting node service').send();
|
||||||
|
|
||||||
|
// import config
|
||||||
import { config } from './config/config.js';
|
import { config } from './config/config.js';
|
||||||
|
|
||||||
// init database
|
// init database
|
||||||
@@ -95,20 +96,38 @@ app.use((err, req, res, next) => {
|
|||||||
res.status(500).send(err.stack);
|
res.status(500).send(err.stack);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*************** START SERVICES ***************/
|
||||||
|
/* Override config
|
||||||
|
* ----------------
|
||||||
|
*
|
||||||
|
* Configuration of services comes from app general config
|
||||||
|
* It can be overriden here by the settings in the db
|
||||||
|
* It can also be overriden on call
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
const s = data.settings;
|
||||||
|
|
||||||
|
const oscIP = s.oscOutIP || config.osc.ipOut;
|
||||||
|
const oscOutPort = s.oscOutPort || config.osc.portOut;
|
||||||
|
const oscInPort = s.oscInPort || config.osc.port;
|
||||||
|
|
||||||
|
const serverPort = s.serverPort || config.server.port;
|
||||||
|
|
||||||
// Start OSC Client
|
// Start OSC Client
|
||||||
// TODO: Move this to function
|
// TODO: Move this to function
|
||||||
const oscClient = new Client('127.0.0.1', 9999);
|
const oscClient = new Client(oscIP, oscOutPort);
|
||||||
|
|
||||||
// create HTTP server
|
// create HTTP server
|
||||||
const server = http.createServer(app);
|
const server = http.createServer(app);
|
||||||
|
|
||||||
export const startServer = (overrideConfig = null) => {
|
export const startServer = (overrideConfig = null) => {
|
||||||
// Setup default port
|
// Setup default port
|
||||||
const serverPort = overrideConfig?.port || config.server.port;
|
const port = overrideConfig?.port || serverPort;
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
const returnMessage = `HTTP Server is listening on port ${serverPort}`;
|
const returnMessage = `HTTP Server is listening on port ${port}`;
|
||||||
server.listen(serverPort, '0.0.0.0', () => console.log(returnMessage));
|
server.listen(port, '0.0.0.0', () => console.log(returnMessage));
|
||||||
|
|
||||||
// init timer
|
// init timer
|
||||||
global.timer = new EventTimer(server, oscClient, config);
|
global.timer = new EventTimer(server, oscClient, config);
|
||||||
@@ -122,14 +141,18 @@ import { initiateOSC, shutdownOSCServer } from './controllers/OscController.js';
|
|||||||
|
|
||||||
export const startOSCServer = (overrideConfig = null) => {
|
export const startOSCServer = (overrideConfig = null) => {
|
||||||
// Setup default port
|
// Setup default port
|
||||||
const oscInPort = overrideConfig?.port || config.osc.port;
|
const oscSettings = {
|
||||||
initiateOSC(config.osc);
|
port: overrideConfig?.port || oscInPort,
|
||||||
|
ipOut: oscIP,
|
||||||
|
portOut: oscOutPort,
|
||||||
|
};
|
||||||
|
initiateOSC(oscSettings);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const startOSCClient = (overrideConfig = null) => {
|
export const startOSCClient = (overrideConfig = null) => {
|
||||||
// Setup default port
|
// Setup default port
|
||||||
const oscOutPort = overrideConfig?.port || config.osc.portOut;
|
const port = overrideConfig?.port || oscOutPort;
|
||||||
console.log('initialise OSC Client at port: ', oscOutPort);
|
console.log('initialise OSC Client at port: ', port);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const shutdown = () => {
|
export const shutdown = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user