-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
84 lines (67 loc) · 2.51 KB
/
app.js
File metadata and controls
84 lines (67 loc) · 2.51 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Set up the server
var express = require('express'),
app = express(),
port = process.env.PORT || 3000,
// Create the HTTP server with the express app as an argument
// to pass to io object
server = require('http').createServer(app);
// Require dependencies
var mongoose= require('mongoose'),
request = require('request'),
cronJob = require('cron').CronJob,
twitter = require('ntwitter');
var configDB = require('./config/database.js');
// Configuration
mongoose.connect(configDB.url); // connect to our database
// set up our express application
app.use(express.logger('dev')); // log every request to the console
app.use(express.bodyParser()); // get information from html forms
// Serve static files
app.set('port', port);
app.use("/js", express.static(__dirname + "/public/js"));
app.use("/css", express.static(__dirname + "/public/css"));
app.use("/partials", express.static(__dirname + "/public/partials"));
app.use("/lib", express.static(__dirname + "/public/lib"));
app.use("/images", express.static(__dirname + "/public/images"));
// LAUNCH *********************************************/
io = require("socket.io").listen(server, {log: false});
/*
ROUTES
*/
// load the socket API and pass in our server & io object
require('./api/twitterAPI.js')(twitter, io);
// load the stat API
require('./api/statAPI.js')(app, io);
// redirect all others to the index (HTML5 history)
// essentially links up all the angularjs partials with their respective paths
app.all("/*", function(req, res, next) {
//console.log('loading page');
res.sendfile("index.html", { root: __dirname + "/public" });
});
// Cronjob hack to keep heroku from shutting down our app
var job = new cronJob({
// Runs every hour
cronTime: '00 */59 * * * *',
onTick: function() {
var date = new Date();
// Make a request to our heroku app page
request('http://graph-therapy.herokuapp.com', function(err, response, body) {
if (!err && response.statusCode == 200) {
console.log('reset herokuapp: ' + date.getHours() + ' ' + date.getMinutes() + ' ' + date.getSeconds() ); // log on success
console.log(response.statusCode);
}
else {
console.log('CRON ERROR!');
console.log(err);
console.log(response.statusCode);
}
});
},
start: false
});
job.start();
// LAUNCH *********************************************/
//Create the server
server.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port') );
});