-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
63 lines (52 loc) · 1.72 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* * * * * * * * * * * * * * * * * * * * * * * * * * *
* CourseLogic Main Server
*
* This is the main server for the CourseLogic website
* and API. It will serve both static files for the
* front-end and properly route API requests for the
* REST-style back-end.
*
* By Justin Bisignano
* * * * * * * * * * * * * * * * * * * * * * * * * * */
var
express = require('express'),
routes = require('./routes'),
database = require('./database'),
app = express(),
schedule = require('node-schedule'),
debug = process.argv[2] == "debug";
// App configuration
console.log('Configuring App...');
if (debug) app.use(express.logger('dev'));
app.use(app.router);
app.use(routes);
app.get('/updateAll', function(req, res){
res.send('Updated');
});
app.use(express.static(__dirname + '/website' ));
// 404
app.use(function(req, res){
res.send(404, "Looking around, eh? Well, see, this page doesn't exist. That's a 404.");
});
// Error handling
app.use(function(err, req, res, next){
console.error(err);
res.send(500, "Internal Server Error! Don't worry, a team of highly \
knowledgable gorillas has been dispatched to check it out.");
});
// Bind the express app to a port, with 80 as the default
app.listen(process.env.PORT || 80);
console.log('App bound to port', process.env.PORT || 80);
// Include the scraper and run it once at startup
console.log('Loading scrapers and running first scrape...')
scraper = require('./scraper');
scraper.main();
// Schedule the scraper service with node-schedule
// This rule is run daily at 5AM
var rule = new schedule.RecurrenceRule();
rule.hour = 5;
rule.minute = 0;
var scraperJob = schedule.scheduleJob(rule, function(){
console.log('Scraping websites as scheduled...');
scraper.main();
});