-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·80 lines (64 loc) · 1.7 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* Module dependencies.
*/
var express = require('express'),
report = require('./routes/report'),
ticket = require('./routes/ticket'),
http = require('http'),
mongoose = require('mongoose'),
yelp = require('./location/findarea.js'),
gcm = require('./gcm/index.js'),
setup = require('./routes/setup'),
rankCron = require('./cron/rank.js');
/**
* Mongo Configuration
*/
mongoose.connect('127.0.0.1', 'plankdb');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'Connection error:'));
var app = express();
app.configure(function() {
app.set('port', process.env.PORT || 3010);
app.use(express.logger('dev'));
app.use(express.bodyParser());
});
// Configure development settings
app.configure('development', function() {
app.use(express.errorHandler());
app.locals.pretty = true;
});
/**
* HTTP-Requests
*/
//Check if the connection is open before setting up
db.once('open', function() {
// Setup the Cronjob
rankCron();
// Profile
app.post('/setup', setup.getConfiguration);
//Reports
app.get('/report', report.getReport);
app.post('/report', report.addReport);
//Tickets
app.get('/ticket/:uuid', ticket.getTicket);
app.post('/ticket', ticket.addTicket);
app.get('/ticket/count', ticket.countValidTickets);
app.post('/ticket/validation', ticket.validationTickets);
//Google Cloud Messenging
// app.get('/gcm', gcm.sendMessage);
app.post('/gcm', gcm.setRegId);
});
/*
Safe exit
*/
process.on('exit', function(err) {
if (!err) {
mongoose.connection.close();
}
});
/**
* Und there shall be light
*/
http.createServer(app).listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});