-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
64 lines (47 loc) · 1.65 KB
/
app.js
File metadata and controls
64 lines (47 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import express from "express";
import dotenv from "dotenv";
import postRoutes from "./routes/postRoutes.js";
import projectRoutes from "./routes/projectRoutes.js";
import usersRoutes from "./routes/userRoutes.js";
import AppError from "./utils/appError.js";
import globalError from "./middleware/globalError.js";
import cookieParser from "cookie-parser";
import rateLimiter from "express-rate-limit";
import mongoSanitize from "express-mongo-sanitize";
import helmet from "helmet";
import xss from "xss-clean";
import hpp from "hpp";
import compression from "compression";
import path from "path";
const app = express();
dotenv.config();
app.get("/", (req, res) => {
res.status(200).send("HELLO WORD");
});
const limiter = rateLimiter({
max: 1000,
windowMs: 60 * 60 * 1000,
message: "To many requests from this ip address ! Please try again in hour",
});
// middlewares
// express-rate-limit to limit the number of requests from a single ip address
// app.use("/api", limiter);
// data sanitization and cleaning against noSQL injections
// app.use(mongoSanitize());
// data sanitization against XSS attacks
// app.use(xss());
app.use(express.json({ extended: true, limit: "10kb" }));
app.use(express.urlencoded({ extended: true, limit: "10kb" }));
// app.use(express.static(path.join(__dirname, "uploads")));
app.use(cookieParser());
// app.use(helmet());
// app.use(compression);
// routes
app.use("/api/blogs", postRoutes);
app.use("/api/projects", projectRoutes);
app.use("/api/users", usersRoutes);
app.all("*", (req, res, next) => {
next(new AppError(`Can not find ${req.originalUrl} on this server`, 404));
});
app.use(globalError);
export default app;