From 522034b61cc2f0a3bfb46b7a2690291d4f1883ce Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Tue, 5 Aug 2025 10:10:53 +0000 Subject: [PATCH] chore: use source instances instead of hard-coded URL for health check --- src/index.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index acaa92f..2f2ee0a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,10 @@ import winston from 'winston'; import { ConfigureController, ManifestController, StreamController } from './controller'; import { BlockedError, logErrorAndReturnNiceString } from './error'; import { createExtractors, ExtractorRegistry } from './extractor'; -import { createSources } from './source'; +import { createSources, Source } from './source'; +import { HomeCine } from './source/HomeCine'; +import { MeineCloud } from './source/MeineCloud'; +import { Soaper } from './source/Soaper'; import { contextFromRequestAndResponse, envGet, envIsProd, Fetcher, StreamResolver } from './utils'; console.log = console.warn = console.error = console.info = console.debug = () => { /* disable in favor of logger */ }; @@ -66,16 +69,18 @@ let lastHealthCheckRequestsTimestamp = 0; addon.get('/health', async (req: Request, res: Response) => { const ctx = contextFromRequestAndResponse(req, res); - const urls = [ - new URL('https://www3.homecine.to'), - new URL('https://soaper.live'), - new URL('https://supervideo.cc'), + const sources: Source[] = [ + new HomeCine(fetcher), + new MeineCloud(fetcher), + new Soaper(fetcher), ]; let blockedCount = 0; let errorCount = 0; - const fetchFactories = urls.map(url => async () => { + const fetchFactories = sources.map(source => async () => { + const url = new URL(source.baseUrl); + try { await fetcher.head(ctx, url, { queueLimit: 1, noCache: true }); } catch (error) { @@ -99,7 +104,7 @@ addon.get('/health', async (req: Request, res: Response) => { logger.warn('IP might be not clean and leading to blocking.', ctx); } - if (errorCount === urls.length) { + if (errorCount === sources.length) { res.status(503).json({ status: 'error' }); } else { res.json({ status: 'ok' });