mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-25 17:09:09 +00:00
register/unregister http
This commit is contained in:
@@ -335,29 +335,29 @@ export const postOscSubscriptions = async (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Create controller for GET request to '/ontime/http'
|
// Create controller for GET request to '/ontime/http'
|
||||||
export const getHTTP = async (req, res: Response<HTTPSettings>) => {
|
export const getHTTP = async (_req, res: Response<HTTPSettings>) => {
|
||||||
const http = DataProvider.getHttp();
|
const http = DataProvider.getHttp();
|
||||||
res.status(200).send(http);
|
res.status(200).send(http);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create controller for POST request to '/ontime/http'
|
// Create controller for POST request to '/ontime/http'
|
||||||
export const postHTTP = async (req: Request<any, any, HTTPSettings>, res: Response) => {
|
export const postHTTP = async (req, res) => {
|
||||||
if (failEmptyObjects(req.body, res)) {
|
if (failEmptyObjects(req.body, res)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const settings = req.body;
|
const httpSettings = req.body;
|
||||||
const httpSettings = DataProvider.getHttp();
|
|
||||||
const hasEnabledChanged = httpSettings.enabledOut !== settings.enabledOut;
|
|
||||||
|
|
||||||
httpSettings.subscriptions = settings.subscriptions;
|
|
||||||
httpSettings.enabledOut = settings.enabledOut;
|
|
||||||
await DataProvider.setHttp(httpSettings);
|
await DataProvider.setHttp(httpSettings);
|
||||||
|
|
||||||
if (hasEnabledChanged) {
|
integrationService.unregister(httpIntegration);
|
||||||
const { message } = httpIntegration.init(httpSettings);
|
|
||||||
logger.info(LogOrigin.Tx, message);
|
// 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);
|
res.send(httpSettings).status(200);
|
||||||
|
|||||||
@@ -31,9 +31,10 @@ export class HttpIntegration implements IIntegration {
|
|||||||
const { subscriptions, enabledOut } = config;
|
const { subscriptions, enabledOut } = config;
|
||||||
|
|
||||||
if (!enabledOut) {
|
if (!enabledOut) {
|
||||||
|
this.httpAgent?.destroy();
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: false,
|
||||||
message: `HTTP integration client disabled`,
|
message: 'HTTP output disabled',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user