2025-09-21 19:35:41 +01:00
|
|
|
import 'dotenv/config';
|
2026-05-21 17:18:08 +01:00
|
|
|
import './instrument';
|
2025-01-18 11:13:05 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
import { API_PORT } from '@api/constants';
|
2025-11-01 15:49:29 +01:00
|
|
|
import { app } from '@api/app';
|
|
|
|
|
import { configureOpenAPI } from '@api/utils/openapi';
|
2026-06-07 18:43:05 +01:00
|
|
|
import { connectRedis } from '@cio/core/utils/redis/redis';
|
|
|
|
|
import { env } from '@cio/core/config/env';
|
2026-05-19 09:59:56 +01:00
|
|
|
import { preloadVerifiedCustomDomainOriginsRegistry } from '@api/utils/origins';
|
2025-09-21 19:35:41 +01:00
|
|
|
import { serve } from '@hono/node-server';
|
|
|
|
|
import { showRoutes } from 'hono/dev';
|
2025-01-18 11:13:05 +01:00
|
|
|
|
2025-09-21 19:35:41 +01:00
|
|
|
// Start server
|
2026-03-09 11:18:22 +01:00
|
|
|
async function startServer() {
|
2025-11-24 01:00:50 +01:00
|
|
|
console.log('Starting server on port:', API_PORT);
|
2025-09-21 19:35:41 +01:00
|
|
|
|
2026-03-11 12:57:44 +01:00
|
|
|
// Connect to Redis (non-blocking: API starts even if Redis fails)
|
2026-03-09 11:18:22 +01:00
|
|
|
await connectRedis();
|
|
|
|
|
|
2026-05-19 09:59:56 +01:00
|
|
|
preloadVerifiedCustomDomainOriginsRegistry().then(() => {
|
|
|
|
|
console.log('Verified custom domain origins preloaded');
|
|
|
|
|
});
|
|
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
serve({ fetch: app.fetch, port: API_PORT });
|
2025-09-21 19:35:41 +01:00
|
|
|
|
2026-05-19 08:15:35 +01:00
|
|
|
if (env.NODE_ENV !== 'production') {
|
|
|
|
|
showRoutes(app, { colorize: true });
|
|
|
|
|
}
|
2025-09-21 19:35:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configureOpenAPI(app);
|
|
|
|
|
|
2026-03-09 11:18:22 +01:00
|
|
|
startServer().catch((error) => {
|
|
|
|
|
console.error('Failed to start server:', error);
|
2026-05-19 08:15:35 +01:00
|
|
|
if (error instanceof Error && error.stack) {
|
|
|
|
|
console.error(error.stack);
|
|
|
|
|
}
|
2026-03-09 11:18:22 +01:00
|
|
|
process.exit(1);
|
|
|
|
|
});
|