32 lines
944 B
TypeScript
32 lines
944 B
TypeScript
|
|
import Fastify from 'fastify';
|
||
|
|
import cors from '@fastify/cors';
|
||
|
|
import helmet from '@fastify/helmet';
|
||
|
|
import pino from 'pino';
|
||
|
|
import { config } from './config/index.js';
|
||
|
|
import { registerRunbookRoutes } from './api/runbooks.js';
|
||
|
|
import { registerApprovalRoutes } from './api/approvals.js';
|
||
|
|
import { registerSlackRoutes } from './slackbot/handler.js';
|
||
|
|
|
||
|
|
const logger = pino({ name: 'dd0c-run', level: config.LOG_LEVEL });
|
||
|
|
|
||
|
|
const app = Fastify({ logger: true });
|
||
|
|
|
||
|
|
await app.register(cors, { origin: config.CORS_ORIGIN });
|
||
|
|
await app.register(helmet);
|
||
|
|
|
||
|
|
// Health check
|
||
|
|
app.get('/health', async () => ({ status: 'ok', service: 'dd0c-run' }));
|
||
|
|
|
||
|
|
// API routes
|
||
|
|
registerRunbookRoutes(app);
|
||
|
|
registerApprovalRoutes(app);
|
||
|
|
registerSlackRoutes(app);
|
||
|
|
|
||
|
|
try {
|
||
|
|
await app.listen({ port: config.PORT, host: '0.0.0.0' });
|
||
|
|
logger.info({ port: config.PORT }, 'dd0c/run SaaS started');
|
||
|
|
} catch (err) {
|
||
|
|
logger.fatal(err, 'Failed to start');
|
||
|
|
process.exit(1);
|
||
|
|
}
|