import "dotenv/config";
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 { registrarRotaCompartilhamento } from "./share.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,
    onError: ({ error, path }) => {
        console.error(`[tRPC erro] ${path ?? "?"}:`, error);
    },
}));
registrarRotasDeUpload(app);
registrarRotaCompartilhamento(app);
servirEstaticos(app);
app.listen(env.porta, () => {
    console.log(`Biblioteca OnFide rodando na porta ${env.porta}`);
});
