mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
Add ready endpoint
This commit is contained in:
parent
07d4dde4f6
commit
2251ddc251
4 changed files with 18 additions and 0 deletions
|
@ -56,6 +56,7 @@ import { hostHeader } from "./middleware/hostHeader";
|
|||
import { getBrandingStats } from "./routes/getBrandingStats";
|
||||
import { getTopBrandingUsers } from "./routes/getTopBrandingUsers";
|
||||
import { getFeatureFlag } from "./routes/getFeatureFlag";
|
||||
import { getReady } from "./routes/getReady";
|
||||
|
||||
export function createServer(callback: () => void): Server {
|
||||
// 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", (req, res) => getStatus(req, res, server));
|
||||
|
||||
router.get("/api/ready", (req, res) => getReady(req, res, server));
|
||||
|
||||
router.get("/api/youtubeApiProxy", youtubeApiProxy);
|
||||
// get user category stats
|
||||
router.get("/api/userStats", getUserStats);
|
||||
|
|
|
@ -193,6 +193,7 @@ addDefaults(config, {
|
|||
minUserIDLength: 30,
|
||||
deArrowPaywall: false,
|
||||
useCacheForSegmentGroups: false,
|
||||
maxConnections: 100
|
||||
});
|
||||
loadFromEnv(config);
|
||||
migrate(config);
|
||||
|
|
13
src/routes/getReady.ts
Normal file
13
src/routes/getReady.ts
Normal 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);
|
||||
}
|
||||
}
|
|
@ -106,6 +106,7 @@ export interface SBSConfig {
|
|||
minUserIDLength: number,
|
||||
deArrowPaywall: boolean,
|
||||
useCacheForSegmentGroups: boolean
|
||||
maxConnections: number;
|
||||
}
|
||||
|
||||
export interface WebhookConfig {
|
||||
|
|
Loading…
Reference in a new issue