-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
46 lines (30 loc) · 854 Bytes
/
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
const express = require('express');
const cors = require('cors');
const path = require('path');
const rateLimit = require("express-rate-limit");
require('dotenv').config();
const { connectDB, runCronJob } = require('./utils')
//Connect to database
connectDB();
//Run cron jobs
runCronJob()
const app = express();
//Route files
const v1 = require('./routes/v1');
const v2 = require('./routes/v2');
app.use(cors());
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'docs')));
// limit each IP to 100 requests every 15 minutes
const limiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 100
});
app.use(limiter);
const port = process.env.PORT || 4915;
//Mount routers
app.use('/', v1);
app.use('/v2', v2);
app.listen(port, () => {
console.log(`Live on http://localhost:${port}`);
});