-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
66 lines (52 loc) · 2.67 KB
/
server.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
65
66
//========================================================================================
/* *
* ALl the imports *
* */
//========================================================================================
// make sure to pass the NODE_ENV variable alongwith the command
const express = require("express");
const bodyParser = require("body-parser");
const { connect } = require("./Database/conn");
const cors = require('cors');
const path = require('path');
const rateLimit = require("express-rate-limit");
//########################################################################################
//========================================================================================
/* *
* All the configurations *
* */
//========================================================================================
const app = express();
const PORT = process.env.PORT || 8080;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cors());
app.use(require('./Middleware/verifyToken.middleware'))
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 400 // limit each IP to 100 requests per windowMs
});
app.use("/api/", limiter);
app.use("/api", require("./routes"));
//########################################################################################
//========================================================================================
/* *
* Start the server *
* */
//========================================================================================
if(PORT!==8080){
app.use(express.static(path.join(__dirname, "client", "build")));
app.use("*", (req, res) => {
res.sendFile(path.join(__dirname, "client", "build", "index.html"));
});
}
app.listen(PORT, async () => {
console.log(`listening on port ${PORT}`);
// connect to mongodb
try {
await connect();
} catch (error) {
console.log(error);
}
});
//########################################################################################