Add ready endpoint

This commit is contained in:
Ajay 2024-04-16 01:13:56 -04:00
parent 07d4dde4f6
commit 2251ddc251
4 changed files with 18 additions and 0 deletions

View file

@ -56,6 +56,7 @@ import { hostHeader } from "./middleware/hostHeader";
import { getBrandingStats } from "./routes/getBrandingStats"; import { getBrandingStats } from "./routes/getBrandingStats";
import { getTopBrandingUsers } from "./routes/getTopBrandingUsers"; import { getTopBrandingUsers } from "./routes/getTopBrandingUsers";
import { getFeatureFlag } from "./routes/getFeatureFlag"; import { getFeatureFlag } from "./routes/getFeatureFlag";
import { getReady } from "./routes/getReady";
export function createServer(callback: () => void): Server { export function createServer(callback: () => void): Server {
// Create a service (the app object is just a callback). // Create a service (the app object is just a callback).
@ -205,6 +206,8 @@ function setupRoutes(router: Router, server: Server) {
router.get("/api/status/:value", (req, res) => getStatus(req, res, server)); router.get("/api/status/:value", (req, res) => getStatus(req, res, server));
router.get("/api/status", (req, res) => getStatus(req, res, server)); router.get("/api/status", (req, res) => getStatus(req, res, server));
router.get("/api/ready", (req, res) => getReady(req, res, server));
router.get("/api/youtubeApiProxy", youtubeApiProxy); router.get("/api/youtubeApiProxy", youtubeApiProxy);
// get user category stats // get user category stats
router.get("/api/userStats", getUserStats); router.get("/api/userStats", getUserStats);

View file

@ -193,6 +193,7 @@ addDefaults(config, {
minUserIDLength: 30, minUserIDLength: 30,
deArrowPaywall: false, deArrowPaywall: false,
useCacheForSegmentGroups: false, useCacheForSegmentGroups: false,
maxConnections: 100
}); });
loadFromEnv(config); loadFromEnv(config);
migrate(config); migrate(config);

13
src/routes/getReady.ts Normal file
View file

@ -0,0 +1,13 @@
import { Request, Response } from "express";
import { Server } from "http";
import { config } from "../config";
export async function getReady(req: Request, res: Response, server: Server): Promise<Response> {
const connections = await new Promise((resolve) => server.getConnections((_, count) => resolve(count))) as number;
if (!connections || connections < config.maxConnections) {
return res.sendStatus(200);
} else {
return res.sendStatus(500);
}
}

View file

@ -106,6 +106,7 @@ export interface SBSConfig {
minUserIDLength: number, minUserIDLength: number,
deArrowPaywall: boolean, deArrowPaywall: boolean,
useCacheForSegmentGroups: boolean useCacheForSegmentGroups: boolean
maxConnections: number;
} }
export interface WebhookConfig { export interface WebhookConfig {