-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
65 lines (53 loc) · 1.55 KB
/
app.js
File metadata and controls
65 lines (53 loc) · 1.55 KB
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
var express = require('express');
var request = require('request');
var eventParser = require('./eventParser.js');
var mentorParser = require('./mentorParser.js');
var app = express();
const ROOT = "./public";
//receive a port, or select default port
app.set('port', (process.env.PORT || 5000));
//log each server request
app.use(function(req, res, next) {
console.log(req.method + " request for " + req.url);
next();
});
//send the home page
app.get(['/', '/index.html', '/index'], function(req, res) {
res.sendFile("/index.html", {root: ROOT});
});
app.get('/events', function(req,res) {
res.send(eventParser.getEvents());
})
app.get('/mentors', function(req, res) {
res.send(mentorParser.getMentors());
})
app.get('/features', function(req, res) {
res.sendFile("features.json", { root: ROOT });
})
//send all other static files
app.use(express.static(ROOT));
//send 404 for anything other request
app.all("*", function(req, res) {
res.status(404);
res.send(JSON.stringify({}));
})
//start listening on the selected port
app.listen(app.get('port'), function () {
console.log('Server listening on port', app.get('port'));
cycle();
setInterval(() => {
cycle();
}, 1500000);
});
//run one scrape cycle on the SSSC website, then ping Heroku
function cycle() {
eventParser.scrape();
mentorParser.scrape();
ping();
}
//gets around the Heroku (hosting service) limit of 30 minutes of inactivity
function ping() {
request('http://sssc-carleton-app-server.herokuapp.com', function (error, response, body) {
console.log('Pinged to keep dyno awake');
});
}