diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts new file mode 100644 index 0000000..65a614c --- /dev/null +++ b/apps/api/src/index.ts @@ -0,0 +1,41 @@ +import "dotenv/config" +import Fastify from "fastify" +import cors from "@fastify/cors" +import cookie from "@fastify/cookie" +import jwt from "@fastify/jwt" +import { setupRoutes } from "./routes/index" + +const server = Fastify({ + logger: true +}) + +const PORT = Number(process.env.PORT) || 4001 +const HOST = "0.0.0.0" + +async function start() { + await server.register(cors, { + origin: "http://localhost:5174", + credentials: true + }) + + await server.register(cookie) + + await server.register(jwt, { + secret: process.env.JWT_SECRET || "dev-secret-change-me" + }) + + server.get("/health", async () => { + return { status: "ok" } + }) + + await setupRoutes(server) + + try { + await server.listen({ port: PORT, host: HOST }) + } catch (err) { + server.log.error(err) + process.exit(1) + } +} + +start() \ No newline at end of file