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/create_http_server.ts
View on GitHub// HTTP Server: Express application setup and lifecycle
// Isolates all HTTP/Express concerns from app orchestration
import express, { type Express, type Request, type Response, type NextFunction } from 'express';
import type { Server } from 'node:http';
import type { Controller } from '../controller';
export type HttpServerDependencies = Readonly<{
readonly controller: Controller;
}>;
export type HttpServer = Readonly<{
readonly start: (port: number) => Promise<void>;
readonly stop: () => Promise<void>;
}>;
export const createHttpServer = (deps: HttpServerDependencies): HttpServer => {
const { controller } = deps;
let server: Server | null = null;
const app: Express = express();
// Middleware
app.use(express.json());
// Mount API routes
app.use('/api/v1', controller.router);
// Error handling middleware
app.use((err: Error, _req: Request, res: Response, _next: NextFunction) => {
console.error('Unhandled error:', err);
res.status(500).json({
error: {
code: 'INTERNAL_ERROR',
message: 'An unexpected error occurred',
},
});
});
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 |