Replaced duplicated server setup code with createServiceApp() factory: - platform-service: 91 → 39 lines - billing-service: 105 → 51 lines (keeps service-specific internal key auth) - growth-service: 83 → 33 lines - tracker-service: 88 → 36 lines Enhanced fastify-core with optional Swagger + Prometheus metrics support. Total reduction: ~208 lines of duplicated boilerplate eliminated. All 246 tests pass.
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
/**
|
|
* Platform Service — Fastify server entry point.
|
|
*
|
|
* Modules: auth, audit, notifications, feature flags.
|
|
* Port: 4003 (configurable via PORT env var).
|
|
*/
|
|
|
|
import { createServiceApp, startService } from '@bytelyst/fastify-core';
|
|
import { authRoutes } from './modules/auth/routes.js';
|
|
import { auditRoutes } from './modules/audit/routes.js';
|
|
import { notificationRoutes } from './modules/notifications/routes.js';
|
|
import { flagRoutes } from './modules/flags/routes.js';
|
|
import { rateLimitRoutes } from './modules/ratelimit/routes.js';
|
|
import { blobRoutes } from './modules/blob/routes.js';
|
|
import { config } from './lib/config.js';
|
|
|
|
const app = await createServiceApp({
|
|
name: 'platform-service',
|
|
version: '0.1.0',
|
|
description: 'Auth, audit, notifications, feature flags, rate limiting',
|
|
corsOrigin: config.CORS_ORIGIN,
|
|
swagger: {
|
|
title: 'Platform Service',
|
|
description: 'Auth, audit, notifications, feature flags, rate limiting',
|
|
port: config.PORT,
|
|
},
|
|
metrics: true,
|
|
});
|
|
|
|
// Register route modules
|
|
await app.register(authRoutes, { prefix: '/api' });
|
|
await app.register(auditRoutes, { prefix: '/api' });
|
|
await app.register(notificationRoutes, { prefix: '/api' });
|
|
await app.register(flagRoutes, { prefix: '/api' });
|
|
await app.register(rateLimitRoutes, { prefix: '/api' });
|
|
await app.register(blobRoutes, { prefix: '/api' });
|
|
|
|
await startService(app, { port: config.PORT, host: config.HOST });
|