import express from "express";
import cookieParser from "cookie-parser";
import * as trpcExpress from "@trpc/server/adapters/express";
import { appRouter } from "../routers.js";
import { createContext } from "./context.js";
import { servirEstaticos } from "./static.js";
import { registrarRotasDeUpload } from "./uploads.js";
import { env } from "./env.js";

const app = express();
app.use(cookieParser());
app.use(express.json());

app.use("/api/trpc", trpcExpress.createExpressMiddleware({ router: appRouter, createContext }));
registrarRotasDeUpload(app);

servirEstaticos(app);

app.listen(env.porta, () => {
  console.log(`Biblioteca OnFide rodando na porta ${env.porta}`);
});
