-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
64 lines (56 loc) · 1.8 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
52
53
54
55
56
57
58
59
60
61
62
63
64
//!importing : start
const cookieParcer=require('cookie-parser');
const express = require("express");
const emptyObject = new Object();
require("dotenv").config();
const notFound = require("./middleware/not-found");
const errorHandlerMiddleWare = require("./middleware/error-handler");
const connectDB = require("./db/connect");
require("express-async-errors");
const authenticationRouter = require("./routes/auth");
const jobsRouter = require("./routes/jobs");
const auth = require("./middleware/authentication");
const cors=require('cors');
const xss=require('xss-clean');
const helmet=require('helmet');
// const rateLimiter=require('express-rate-limit');
const refreshToken = require("./middleware/refreshToken");
const refreshRouter = require('./routes/refresh');
//!importing : end
const app = express();
// app.use(
// rateLimiter({
// windowMs: 15 * 60 * 1000, // 15 minutes
// max: 100, // limit each IP to 100 requests per windowMs
// })
// );
app.use(cors()); //! first one
app.use(xss());
app.use(helmet());
app.use(express.json());
app.use(cookieParcer());
//! middlewares : start
app.get("/", (req, res) => {
res.send("hello there");
});
app.use("/api/v1/auth", authenticationRouter);
app.use("/api/v1/refresh",refreshRouter);
app.use(auth);//! every route in jobs now is secure
app.use("/api/v1/jobs", jobsRouter);
//! middlewares : end
//! handling errors + other middlewares : start
app.use(notFound);
app.use(errorHandlerMiddleWare);
//! handling errors + other middlewares : end
const port = process.env.PORT || 3000;
async function start() {
try {
await connectDB(process.env.MONGO_URI); //todo please test it without the await
app.listen(port, () => {
console.log(`Server Is listening to the ${port} port...`);
});
} catch (error) {
console.log(error);
}
}
start();