-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (42 loc) · 1.51 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
require('dotenv').config();
const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const bodyParser = require('body-parser');
const db = process.env.M_LAB_URL_NEW;
const app = express();
const port = process.env.PORT || 1337;//8000;
var helmet = require('helmet');
var RateLimit = require('express-rate-limit');
const https = require('https');
var limiter = new RateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 500, // limit each IP to 100 requests per windowMs
delayMs: 0, // disable delaying - full speed until the max limit is reached
message: "Too many accounts created from this IP, please try again after 15 minutes"
});
app.use(limiter);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use('/static', express.static('public'))
app.use(helmet())
MongoClient.connect(db, (err, database) => {
if (err) return console.log(err)
var myDB = database.db('symbolsapi');//mLab
//var myDB = database.db('SymbolsDB');//mongoDb Atlas
require('./app/routes')(app, myDB);
app.listen(port, () => {
console.log('We are live on ' + port);
});
setInterval(()=>{
let start = myDB.collection('symbols').find({id: 1})
.project({id: 1})
.limit(1)
.sort({id: 1});
start.toArray().then(res=>{
//console.log(res);
})
https.get('https://symbotalkapiv1.azurewebsites.net', ()=>{
console.log('keeping the instance alive');
});
}, 20000);
})