provapraticabackend/dist/index.js

41 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2026-06-09 13:01:53 +02:00
import { ExpressAuth } from "@auth/express";
import dotenv from "dotenv";
import express from "express";
2026-06-09 14:57:40 +02:00
import path from "node:path";
import { fileURLToPath } from "node:url";
2026-06-09 13:01:53 +02:00
import { authConfig } from "./auth/config.js";
import { corsMiddleware } from "./config/cors.js";
2026-06-09 14:57:40 +02:00
import { swaggerServe, swaggerSetup } from "./config/swagger.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();
const port = Number(process.env.PORT) || 3003;
app.set("trust proxy", 1);
app.use(corsMiddleware);
2026-06-09 13:01:53 +02:00
app.use(express.json());
app.options(/.*/, corsMiddleware);
app.get("/api/health", (_req, res) => {
res.json({ status: "ok" });
});
2026-06-09 14:57:40 +02:00
const swaggerEnabled = process.env.SWAGGER_ENABLED !== "false";
if (swaggerEnabled) {
const __dirname = path.dirname(fileURLToPath(import.meta.url));
app.use("/api/docs", swaggerServe, swaggerSetup);
app.get("/api/docs/openapi.json", (_req, res) => {
res.sendFile(path.join(__dirname, "openapi/openapi.json"));
});
}
2026-06-09 13:38:58 +02:00
app.use("/api/auth", 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);
app.listen(port, "0.0.0.0", () => {
console.log(`Backend in ascolto sulla porta ${port}`);
});
//# sourceMappingURL=index.js.map