LiorCohen/sdd / plugin/fullstack-typescript/skills/components/backend/backend-scaffolding
backend-scaffolding
VerifiedScaffolds Node.js/TypeScript backend components with CMDO architecture, driven by component settings.
templates/src/operator/lifecycle_probes.ts
View on GitHub// Lifecycle Probes: Kubernetes-style health check endpoints
// Runs on separate port from main API server for infrastructure monitoring
import express, { type Express, type Request, type Response } from "express";
import type { Server } from "node:http";
export type LifecycleProbesDependencies = Readonly<{
readonly getAppState: () => string;
}>;
export type LifecycleProbes = Readonly<{
readonly start: (port: number) => Promise<void>;
readonly stop: () => Promise<void>;
}>;
export const createLifecycleProbes = (
deps: LifecycleProbesDependencies
): LifecycleProbes => {
const { getAppState } = deps;
let server: Server | null = null;
const app: Express = express();
// Health probe (use for startupProbe and livenessProbe)
// If the server responds, the process is alive
app.get("/health", (_req: Request, res: Response) => {
res.json({ status: "ok" });
});
// Readiness probe (use for readinessProbe)
// Only ready when app is fully running and can serve traffic
app.get("/readiness", (_req: Request, res: Response) => {
const state = getAppState();
if (state === "RUNNING") {
res.json({ status: "ready" });
} else {
res.status(503).json({ status: "not_ready", state });
}
});
const start = async (port: number): Promise<void> => {
await new Promise<void>((resolve, reject) => {
server = app.listen(port, () => {
resolve();
});
server.on("error", reject);
});
};
const stop = async (): Promise<void> => {
if (!server) {
return;
}
await new Promise<void>((resolve, reject) => {
server!.close((err) => {
if (err) {
reject(err);
return;
}
resolve();
});
});
server = null;
};
return { start, stop };
};
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |