2026-06-09 13:01:53 +02:00
|
|
|
import { ExpressAuth } from "@auth/express";
|
|
|
|
|
import dotenv from "dotenv";
|
|
|
|
|
import express from "express";
|
|
|
|
|
import { authConfig } from "./auth/config.js";
|
2026-06-09 13:21:03 +02:00
|
|
|
import { corsMiddleware } from "./config/cors.js";
|
2026-06-09 13:01:53 +02:00
|
|
|
import { errorHandler } from "./middleware/errorHandler.js";
|
|
|
|
|
import categorieRouter from "./routes/categorie.js";
|
|
|
|
|
import rimborsiRouter from "./routes/rimborsi.js";
|
|
|
|
|
import statisticheRouter from "./routes/statistiche.js";
|
|
|
|
|
import utentiRouter from "./routes/utenti.js";
|
|
|
|
|
dotenv.config();
|
|
|
|
|
const app = express();
|
2026-06-09 11:22:41 +02:00
|
|
|
const port = Number(process.env.PORT) || 3003;
|
|
|
|
|
app.set("trust proxy", 1);
|
2026-06-09 13:21:03 +02:00
|
|
|
app.use(corsMiddleware);
|
2026-06-09 13:01:53 +02:00
|
|
|
app.use(express.json());
|
2026-06-09 13:21:03 +02:00
|
|
|
app.options(/.*/, corsMiddleware);
|
2026-06-09 11:22:41 +02:00
|
|
|
app.get("/api/health", (_req, res) => {
|
|
|
|
|
res.json({ status: "ok" });
|
|
|
|
|
});
|
2026-06-09 13:29:01 +02:00
|
|
|
// Express 5: il wildcard * deve essere nominato (es. *splat)
|
|
|
|
|
app.use("/api/auth/{*splat}", ExpressAuth(authConfig));
|
2026-06-09 13:01:53 +02:00
|
|
|
app.use("/api/utenti", utentiRouter);
|
|
|
|
|
app.use("/api/categorie-spesa", categorieRouter);
|
|
|
|
|
app.use("/api/rimborsi", rimborsiRouter);
|
|
|
|
|
app.use("/api/statistiche", statisticheRouter);
|
|
|
|
|
app.use(errorHandler);
|
2026-06-09 11:22:41 +02:00
|
|
|
app.listen(port, "0.0.0.0", () => {
|
|
|
|
|
console.log(`Backend in ascolto sulla porta ${port}`);
|
|
|
|
|
});
|
|
|
|
|
//# sourceMappingURL=index.js.map
|