-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
173 lines (147 loc) · 5.01 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
var express = require('express'),
app = express(),
fs = require('fs'),
path = require('path'),
pfxFilePath = path.resolve(__dirname, 'ssl/client.p12'),
pfxPasswordPath = path.resolve(__dirname, 'ssl/password'),
request = require('request'),
bodyParser = require('body-parser'),
mustacheExpress = require('mustache-express'),
exec = require('child_process').exec;
var config;
fs.readFile('config.json', 'utf8', function (err, data) {
if (err) throw err;
config = JSON.parse(data)
});
app.use(express.static('static'));
app.use(bodyParser.json());
app.engine('html', mustacheExpress());
function urlWithSSLOptions(url) {
var options = {};
options.url = url;
options.agentOptions = {
pfx: fs.readFileSync(pfxFilePath),
passphrase: fs.readFileSync(pfxPasswordPath),
securityOptions: 'SSL_OP_NO_SSLv3'
};
return options;
}
//------------------ API ------------------//
app.get('/ListEpics', function (req, res) {
var queryUrl = config.jiradomain + "/rest/greenhopper/1.0/xboard/plan/backlog/epics?rapidViewId=" + config.rapidViewId;
request.get(urlWithSSLOptions(queryUrl), function (error, response, body) {
if (!error && response.statusCode == 200) {
res.send(JSON.parse(body));
}
});
});
app.get('/LoadTickets', function (req, res) {
var project = req.query.project;
var status = req.query.status;
var epic = req.query.epic;
var queryUrl = config.jiradomain + "/rest/api/2/search?jql=";
queryUrl += "project=" + config.projects[project];
queryUrl += " AND status=" + config.statuses[status];
queryUrl += " AND \"Epic Link\"=" + epic;
queryUrl = encodeURI(queryUrl);
console.log("URL: " + req.url);
console.log("JIRA URL: " + queryUrl);
request.get(urlWithSSLOptions(queryUrl), function (error, response, body) {
if (!error && response.statusCode == 200) {
res.send(JSON.parse(body));
}
});
});
//TODO for dev only
app.get('/OfflineTickets', function (req, res) {
fs.readFile('offlinedata/tickets.json', 'utf8', function (err, data) {
if (err) throw err;
res.send(JSON.parse(data));
});
});
//TODO for dev only
app.get('/OfflineEpics', function (req, res) {
fs.readFile('offlinedata/epics.json', 'utf8', function (err, data) {
if (err) throw err;
res.send(JSON.parse(data));
});
});
app.get('/speakNextTicket', function (req, res) {
if(req.query.number) {
exec ('omxplayer static/audio/nextTicketBell.wav', function(error, stdout, stderr) {
if(error == null) {
console.log(stdout);
exec ('echo "Testing Ticket number '+ req.query.number+' being discussed now" | festival --tts', function(error, stdout, stderr) {
if(error == null)
{
res.send("Spoke "+ req.query.number);
console.log(stdout);
}
else {
res.send("Error: "+ stderr);
console.log(stderr);
}
});
}
else {
res.send("Error: "+ stderr);
console.log(stderr);
}
});
}
else {
res.send("Error: no 'number' parameter");
}
});
app.get('/soundEndOfStandUp', function (req, res) {
exec ('omxplayer static/audio/thatsAllFolks.mp3', function(error, stdout, stderr) {
if(error == null) {
res.send("Sounded end of standup");
console.log(stdout);
}
else {
res.send("Error: "+ stderr);
console.log(stderr);
}
});
});
app.get('/sayTimerStarted', function (req, res) {
exec ('echo "Testing Countdown Timer has started, please proceed" | festival --tts', function(error, stdout, stderr) {
if(error == null) {
res.send("Spoke prompt");
console.log(stdout);
}
else {
res.send("Error: "+ stderr);
console.log(stderr);
}
});
});
app.get('/thirtySecondsLeft', function (req, res) {
exec ('echo "Testing Warn-ing, Thirty Seconds remaining for this ticket" | festival --tts', function(error, stdout, stderr) {
if(error == null) {
res.send("Spoke warning");
console.log(stdout);
}
else {
res.send("Error: "+ stderr);
console.log(stderr);
}
});
});
//------------------ ROUTE FOR INDEX AND PARTIALS ------------------//
//app.get('/', function(req, res) {
// res.render('title.html');
//});
app.get('/', function(req, res) {
res.render('epics.html');
});
app.get('/standup', function(req, res) {
res.render('standup.html');
});
//------------------ START SERVER ------------------//
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});