The Express framework, built on top of Node.js, is a popular framework known for its freedom and complete control over how you build your project. However, this freedom can be detrimental, especially for those with limited experience or those wanting to create large projects using Express.Nest was the ideal solution to this problem with its clear organization and architecture, making it the preferred choice for companies and the most suitable for large and expanding projects.
import express from "express";
import * as dotenv from "dotenv";
import helmet from "helmet";
import cors from "cors";
import { generalLimiter } from "./middleware/rate-limit";
import adminRoutes from "./modules/admin/admin.routes";
import userRoutes from "./modules/users/users.routes";
import postRoutes from "./modules/posts/posts.routes";
import followRoutes from "./modules/follows/follows.routes";
import groupRoutes from "./modules/groups/groups.routes";
import notificationsRoutes from "./modules/notifications/notifictions.routes"
import { authUser } from "./middleware/auth.middleware";
import swaggerui from "swagger-ui-express";
import swaggerDocument from "./docs/swagger.json";
import handleErrors from "./middleware/error.middleware";
import commentRouter from "./modules/comments/comments.route";
import { sanitizeRequest } from "./middleware/sanitize";
dotenv.config();
const app = express();
// Middleware
app.use(helmet());
app.use(cors({
origin : "*",
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['Content-Type', 'Authorization']
}));
app.use(express.json());
app.use(sanitizeRequest)
app.set('trust proxy', 1);
app.use(generalLimiter);
//API Routes
app.use("/api/admin", adminRoutes);
app.use("/api/users", userRoutes);
app.use("/api/posts", postRoutes);
app.use("/api/follows", followRoutes);
app.use("/api/groups", groupRoutes);
app.use("/api/notifications", notificationsRoutes)
app.use("/api/comments", commentRouter)
app.use(handleErrors);
app.use("/docs",authUser,swaggerui.serve, swaggerui.setup(swaggerDocument));
export default app;
Top comments (0)