provapraticabackend/dist/index.js
AV77web 5184669185
All checks were successful
Deploy to VPS / build (push) Successful in 17s
Deploy to VPS / deploy (push) Successful in 30s
implementato Swagger nel backend
2026-06-09 14:57:40 +02:00

41 lines
No EOL
1.6 KiB
JavaScript

import { ExpressAuth } from "@auth/express";
import dotenv from "dotenv";
import express from "express";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { authConfig } from "./auth/config.js";
import { corsMiddleware } from "./config/cors.js";
import { swaggerServe, swaggerSetup } from "./config/swagger.js";
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);
app.use(express.json());
app.options(/.*/, corsMiddleware);
app.get("/api/health", (_req, res) => {
res.json({ status: "ok" });
});
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"));
});
}
app.use("/api/auth", ExpressAuth(authConfig));
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