From 52a61777ed42d8c3e02f7d1b7d647fa161c82926 Mon Sep 17 00:00:00 2001 From: arc-alex Date: Wed, 29 Nov 2023 11:29:04 +0100 Subject: [PATCH] register/unregister http --- .../src/controllers/ontimeController.ts | 22 +++++++++---------- .../integration-service/HttpIntegration.ts | 5 +++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/apps/server/src/controllers/ontimeController.ts b/apps/server/src/controllers/ontimeController.ts index 77dd0d7c6..cf80ec66b 100644 --- a/apps/server/src/controllers/ontimeController.ts +++ b/apps/server/src/controllers/ontimeController.ts @@ -335,29 +335,29 @@ export const postOscSubscriptions = async (req, res) => { }; // Create controller for GET request to '/ontime/http' -export const getHTTP = async (req, res: Response) => { +export const getHTTP = async (_req, res: Response) => { const http = DataProvider.getHttp(); res.status(200).send(http); }; // Create controller for POST request to '/ontime/http' -export const postHTTP = async (req: Request, res: Response) => { +export const postHTTP = async (req, res) => { if (failEmptyObjects(req.body, res)) { return; } try { - const settings = req.body; - const httpSettings = DataProvider.getHttp(); - const hasEnabledChanged = httpSettings.enabledOut !== settings.enabledOut; - - httpSettings.subscriptions = settings.subscriptions; - httpSettings.enabledOut = settings.enabledOut; + const httpSettings = req.body; await DataProvider.setHttp(httpSettings); - if (hasEnabledChanged) { - const { message } = httpIntegration.init(httpSettings); - logger.info(LogOrigin.Tx, message); + integrationService.unregister(httpIntegration); + + // TODO: this update could be more granular, checking that relevant data was changed + const { success, message } = httpIntegration.init(httpSettings); + logger.info(LogOrigin.Tx, message); + + if (success) { + integrationService.register(httpIntegration); } res.send(httpSettings).status(200); diff --git a/apps/server/src/services/integration-service/HttpIntegration.ts b/apps/server/src/services/integration-service/HttpIntegration.ts index ce08eb549..5e6ddde33 100644 --- a/apps/server/src/services/integration-service/HttpIntegration.ts +++ b/apps/server/src/services/integration-service/HttpIntegration.ts @@ -31,9 +31,10 @@ export class HttpIntegration implements IIntegration { const { subscriptions, enabledOut } = config; if (!enabledOut) { + this.httpAgent?.destroy(); return { - success: true, - message: `HTTP integration client disabled`, + success: false, + message: 'HTTP output disabled', }; }