refactor: improve console visibility

This commit is contained in:
Carlos Valente
2024-06-08 22:58:06 +02:00
committed by Carlos Valente
parent b99cf5f255
commit 715600a514
3 changed files with 36 additions and 12 deletions
+13 -9
View File
@@ -20,6 +20,7 @@ import {
clearUploadfolder,
} from './setup/index.js';
import { ONTIME_VERSION } from './ONTIME_VERSION.js';
import { consoleGreen } from './utils/console.js';
// Import Routers
import { appRouter } from './api-data/index.js';
@@ -44,6 +45,7 @@ import { populateDemo } from './setup/loadDemo.js';
import { getState } from './stores/runtimeState.js';
import { initRundown } from './services/rundown-service/RundownService.js';
import { generateCrashReport } from './utils/generateCrashReport.js';
import { getNetworkInterfaces } from './utils/networkInterfaces.js';
console.log(`Starting Ontime version ${ONTIME_VERSION}`);
@@ -158,11 +160,8 @@ export const startServer = async () => {
const { serverPort } = DataProvider.getSettings();
const returnMessage = `Ontime is listening on port ${serverPort}`;
expressServer = http.createServer(app);
socket.init(expressServer);
logger.info(LogOrigin.Server, returnMessage);
/**
* Module initialises the services and provides initial payload for the store
@@ -200,7 +199,15 @@ export const startServer = async () => {
// eventStore set is a dependency of the services that publish to it
messageService.init(eventStore.set.bind(eventStore));
expressServer.listen(serverPort, '0.0.0.0');
expressServer.listen(serverPort, '0.0.0.0', () => {
const nif = getNetworkInterfaces();
for (const key of Object.keys(nif)) {
consoleGreen(`Ontime running on: http://${nif[key].address}:${serverPort}`);
}
});
const returnMessage = `Ontime is listening on port ${serverPort}`;
logger.info(LogOrigin.Server, returnMessage);
return { message: returnMessage, serverPort };
};
@@ -251,7 +258,6 @@ export const shutdown = async (exitCode = 0) => {
await restoreService.clear();
}
// TODO: Clear token
expressServer?.close();
runtimeService.shutdown();
integrationService.shutdown();
@@ -263,16 +269,14 @@ export const shutdown = async (exitCode = 0) => {
process.on('exit', (code) => console.log(`Ontime shutdown with code: ${code}`));
process.on('unhandledRejection', async (error) => {
console.error('Error: unhandled rejection', error);
generateCrashReport(error);
logger.error(LogOrigin.Server, `Error: unhandled rejection ${error}`);
logger.error(LogOrigin.Server, `Uncaught exception | ${error}`);
await shutdown(1);
});
process.on('uncaughtException', async (error) => {
console.error('Error: uncaught exception', error);
generateCrashReport(error);
logger.error(LogOrigin.Server, `Error: uncaught exception ${error}`);
logger.error(LogOrigin.Server, `Uncaught exception | ${error}`);
await shutdown(1);
});