-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.js
51 lines (39 loc) · 1.23 KB
/
app.js
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
require("express-async-errors")
const express = require("express")
const app = express()
require("dotenv").config()
require("./src/db/dbConnection")
const port = process.env.PORT || 5002
const router = require("./src/routers")
const errorHandlerMiddleware = require("./src/middlewares/errorHandler")
const cors = require("cors")
const corsOptions = require("./src/helpers/corsOptions")
const mongoSanitize = require('express-mongo-sanitize');
const path = require("path")
const apiLimiter = require("./src/middlewares/rateLimit")
const moment = require("moment-timezone")
moment.tz.setDefault("Europe/Istanbul")
// Middlewares
app.use(express.json())
app.use(express.json({limit: "50mb"}))
app.use(express.urlencoded({limit: "50mb", extended: true, parameterLimit: 50000}))
app.use(express.static(path.join(__dirname, "public")))
app.use("/uploads", express.static(__dirname))
app.use(cors(corsOptions))
app.use("/api", apiLimiter)
app.use(
mongoSanitize({
replaceWith: '_',
}),
);
app.use("/api", router)
app.get("/", (req, res) => {
res.json({
message: "Hoş Geldiniz"
})
})
// hata yakalama
app.use(errorHandlerMiddleware)
app.listen(port, () => {
console.log(`Server ${port} portundan çalışıyor ...`);
})