feat: add health endpoint

This commit is contained in:
WebStreamr 2025-07-18 08:19:20 +00:00
parent 5555ba7040
commit cd19f1c999
No known key found for this signature in database

View file

@ -6,7 +6,7 @@ import winston from 'winston';
import { ConfigureController, ManifestController, StreamController } from './controller';
import { createExtractors, ExtractorRegistry } from './extractor';
import { CineHDPlus, Cuevana, Eurostreaming, Frembed, FrenchCloud, KinoGer, MegaKino, MeineCloud, MostraGuarda, Movix, PrimeWire, Soaper, Source, StreamKiste, VerHdLink, VidSrc, VixSrc } from './source';
import { envGet, envIsProd, Fetcher, StreamResolver } from './utils';
import { contextFromRequest, envGet, envIsProd, Fetcher, StreamResolver } from './utils';
const logger = winston.createLogger({
transports: [
@ -81,6 +81,21 @@ addon.get('/', (_req: Request, res: Response) => {
res.redirect('/configure');
});
addon.get('/health', async (req: Request, res: Response) => {
const ctx = contextFromRequest(req);
try {
const ip = await fetcher.text(ctx, new URL('https://api.ipify.org'));
res.json({ status: 'ok', ip });
} catch (error) {
const cause = (error as Error & { cause?: unknown }).cause;
logger.error(`health check error: ${error}, cause: ${cause}`, ctx);
res.status(503).json({ status: 'error' });
}
});
const port = parseInt(envGet('PORT') || '51546');
addon.listen(port, () => {
logger.info(`Add-on Repository URL: http://127.0.0.1:${port}/manifest.json`);