import "reflect-metadata"; import { NestFactory } from "@nestjs/core"; import { FastifyAdapter, type NestFastifyApplication } from "@nestjs/platform-fastify"; import { AppModule } from "./app.module.js"; import { serve } from "inngest/node"; import { inngest as workerInngest, functions } from "@courtmitra/worker"; async function bootstrap() { const app = await NestFactory.create(AppModule, new FastifyAdapter(), { logger: ["error", "warn", "log"], }); app.setGlobalPrefix("api"); app.enableCors({ origin: true }); // Mount Inngest worker handler on /api/inngest (combined container) const inngestHandler = serve({ client: workerInngest, functions }); const fastify = app.getHttpAdapter().getInstance(); fastify.route({ method: ["GET", "POST", "PUT"], url: "/api/inngest", handler: async (request: any, reply: any) => { reply.hijack(); inngestHandler(request.raw, reply.raw); }, }); const port = Number(process.env.API_PORT ?? process.env.PORT ?? 3001); await app.listen(port, "0.0.0.0"); console.log(`[api] listening on http://localhost:${port}/api`); console.log(`[worker] inngest endpoint on http://localhost:${port}/api/inngest`); } bootstrap().catch((err) => { console.error(err); process.exit(1); });