-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (34 loc) · 989 Bytes
/
Copy pathserver.js
File metadata and controls
49 lines (34 loc) · 989 Bytes
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
express = require('express');
var app = express();
app.get('/index.html', function(req, res){
var pos = Math.floor((Math.random()*10)+1);
var body = 'try the /ball url.';
res.setHeader('Content-Type', 'text/plain');
res.setHeader('Content-Length', body.length);
res.end(body);
});
var choices = [
'No',
'Yes',
'Ask me later',
'Better not',
'Definitely Not!',
'Do not hesitate',
'Green',
'Red',
'Vote Yes',
'Vote No'
]
app.get('/ball', function(req, res){
var pos = Math.floor((Math.random()*10)+1);
// var body = 'magicnodeball : { response : \'' + choices[pos-1] + '\'}';
var rval = {};
rval.magicnodeball = {};
rval.magicnodeball.reponse = choices[pos-1];
// res.setHeader('Content-Type', 'application/json');
// res.setHeader('Content-Length', body.length);
// res.end(body);
res.json(rval);
});
app.listen(process.env.PORT || 2000);
console.log('Listening on port ' + process.env.PORT || 2000);