-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
58 lines (46 loc) · 1.52 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
require('dotenv').config()
const express = require('express');
const mongoose = require('mongoose');
const path = require('path');
const routes = require('./backend/routes');
const UntappdClient = require('untappd-js');
const { Checkin, Beer } = require('./backend/models');
const { startAll } = require('./backend/feed-proc');
const twitterBot = require('./backend/twitter-bot');
mongoose.Promise = require('bluebird');
var untappd = new UntappdClient();
const CLIENT_SECRET = process.env.UNTAPPD_CLIENT_SECRET;
const CLIENT_ID = process.env.UNTAPPD_CLIENT_ID;
untappd.setClientId(CLIENT_ID);
untappd.setClientSecret(CLIENT_SECRET);
const PORT = process.env.PORT || '3001';
const MONGO_URL = process.env.MONGO_URL || 'mongodb://localhost/beerfeed';
mongoose.connect(MONGO_URL)
const app = express();
app.use(express.static(path.join(__dirname, 'build')));
app.use('/', routes(untappd));
const server = app.listen(PORT, function () {
const { address, port } = server.address();
console.log(`Beer feed listening at http://${address}:${port}`);
});
function removeOld(){
const twoDays = new Date(new Date() - 1000 * 60 * 60 * 24 * 2);
Checkin.find({ checkin_created : { $lt : twoDays } })
.remove((err, result) => {
if(err){
console.log(err)
}
})
Beer.find({last_updated : { $lt : twoDays } })
.remove((err) => {
if(err){
console.log(err)
}
})
}
removeOld()
setInterval(removeOld, 1000*60*10) // Filter old checkins every 10 minutes
if(process.env.NODE_ENV === 'production'){
startAll();
twitterBot.startAll();
}