chore: use source instances instead of hard-coded URL for health check

This commit is contained in:
WebStreamr 2025-08-05 10:10:53 +00:00
parent faa91ce238
commit 522034b61c
No known key found for this signature in database

View file

@ -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' });