Files
llm-backend/src/index.ts

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2026-01-27 17:47:41 -08:00
import Fastify from "fastify";
import cors from "@fastify/cors";
import swagger from "@fastify/swagger";
import swaggerUI from "@fastify/swagger-ui";
import sensible from "@fastify/sensible";
import { env } from "./env.js";
import { registerRoutes } from "./routes.js";
const app = Fastify({
logger: {
transport: {
target: "pino-pretty",
options: { colorize: true, translateTime: "SYS:standard" },
},
},
});
await app.register(cors, { origin: true, credentials: true });
await app.register(swagger, {
openapi: {
info: {
title: "LLM Multiplexer Backend",
version: "0.1.0",
},
},
});
await app.register(swaggerUI, { routePrefix: "/docs" });
await app.register(sensible);
app.setErrorHandler((err, _req, reply) => {
const e = err as any;
const statusCode = e.statusCode ?? 500;
reply.status(statusCode).send({
error: true,
message: e.message ?? String(e),
statusCode,
});
});
await registerRoutes(app);
await app.listen({ port: env.PORT, host: env.HOST });
app.log.info(`listening on http://${env.HOST}:${env.PORT}`);