import "./env.js"; import Fastify from "fastify"; import cors from "@fastify/cors"; import { ensureSchema } from "./db/client.js"; import { healthRoutes } from "./routes/health.js"; import { deviceRoutes } from "./routes/devices.js"; import { serviceRoutes } from "./routes/services.js"; import { categoryRoutes } from "./routes/categories.js"; import { scanRoutes } from "./routes/scan.js"; import { logRoutes } from "./routes/logs.js"; const PORT = Number(process.env.PORT ?? 3001); const HOST = process.env.HOST ?? "0.0.0.0"; async function main() { const app = Fastify({ logger: { level: process.env.LOG_LEVEL ?? "info", transport: process.env.NODE_ENV !== "production" ? { target: "pino-pretty", options: { colorize: true } } : undefined, }, }); await app.register(cors, { origin: process.env.CORS_ORIGIN ?? true, }); ensureSchema(); await app.register(healthRoutes); await app.register(deviceRoutes); await app.register(serviceRoutes); await app.register(categoryRoutes); await app.register(scanRoutes); await app.register(logRoutes); app.get("/", async () => { return { name: "LaunchPad API", status: "running" }; }); try { await app.listen({ port: PORT, host: HOST }); app.log.info(`LaunchPad backend läuft auf http://${HOST}:${PORT}`); } catch (err) { app.log.error(err); process.exit(1); } } main();