-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
49 lines (43 loc) · 1.15 KB
/
index.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
require('dotenv').config();
const http = require('http');
const express = require('express');
const rateLimit = require("express-rate-limit");
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
const port = process.env.PORT || 3000;
const server = http.createServer(app);
const router = require('./routes/router.js');
const setupWs = require('./helpers/ws.js');
const mongoose = require('mongoose');
/*
// Rate Limiter Setup
const limiter = rateLimit({
windowMs: 5 * 60 * 1000, // 5 minutes
max: 100, // limit each IP to 100 requests per windowMs
message: "You have been rate limited."
});
app.use(limiter);
*/
mongoose.connect(process.env.MONGO, {
useNewUrlParser: true,
useUnifiedTopology: true
});
let db = mongoose.connection;
db.once("open", () => {
console.log("Connected to MongoDB");
});
db.on("error", (err) => {
console.log(err);
});
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(bodyParser.json());
app.use(cors());
app.use(express.static('static'));
app.use('/', router);
setupWs(server);
server.listen(port, () => {
console.log("PuzzleDash Server started.");
})