2025-04-30 18:26:39 +00:00
|
|
|
import { globalErrorHandler, logger } from "@rdx/core";
|
2025-04-27 20:47:47 +00:00
|
|
|
import dotenv from "dotenv";
|
|
|
|
|
import express, { Application } from "express";
|
|
|
|
|
import helmet from "helmet";
|
|
|
|
|
import responseTime from "response-time";
|
|
|
|
|
|
|
|
|
|
dotenv.config();
|
|
|
|
|
|
|
|
|
|
export function createApp(): Application {
|
|
|
|
|
const app = express();
|
|
|
|
|
app.set("port", process.env.PORT ?? 3002);
|
|
|
|
|
|
|
|
|
|
// secure apps by setting various HTTP headers
|
|
|
|
|
app.disable("x-powered-by");
|
|
|
|
|
|
|
|
|
|
// Middlewares
|
|
|
|
|
app.use(express.json());
|
|
|
|
|
app.use(express.text());
|
|
|
|
|
app.use(express.urlencoded({ extended: true }));
|
|
|
|
|
|
|
|
|
|
app.use(responseTime()); // set up the response-time middleware
|
|
|
|
|
|
|
|
|
|
// secure apps by setting various HTTP headers
|
|
|
|
|
app.use(helmet());
|
|
|
|
|
|
|
|
|
|
// Middleware global para desactivar la caché en todas las rutas
|
|
|
|
|
app.use((req, res, next) => {
|
|
|
|
|
res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
|
|
|
|
|
res.setHeader("Pragma", "no-cache");
|
|
|
|
|
res.setHeader("Expires", "0");
|
|
|
|
|
res.setHeader("etag", "false");
|
|
|
|
|
next(); // Continúa con la siguiente función middleware o la ruta
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Inicializar Auth Provider
|
|
|
|
|
app.use((req, res, next) => {
|
|
|
|
|
//authProvider.initialize();
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.use((req, _, next) => {
|
|
|
|
|
logger.info(`▶️ Incoming request ${req.method} to ${req.path}`);
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Gestión global de errores.
|
|
|
|
|
// Siempre al final de la cadena de middlewares
|
|
|
|
|
// y después de las rutas.
|
|
|
|
|
app.use(globalErrorHandler);
|
|
|
|
|
|
|
|
|
|
return app;
|
|
|
|
|
}
|