feat: add health endpoint
This commit is contained in:
parent
5555ba7040
commit
cd19f1c999
1 changed files with 16 additions and 1 deletions
17
src/index.ts
17
src/index.ts
|
|
@ -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`);
|
||||
|
|
|
|||
Loading…
Reference in a new issue