Skip to content

Commit 8c53381

Browse files
committed
make json
1 parent c4b985b commit 8c53381

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

‎node/server.js‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
express = require('express');
22
var app = express();
33

4-
app.get('/hello.txt', function(req, res){
4+
app.get('/index.html', function(req, res){
55

66
var pos = Math.floor((Math.random()*10)+1);
77

8-
var body = 'Hello World : '+pos;
8+
var body = 'try the /ball url.';
99
res.setHeader('Content-Type', 'text/plain');
1010
res.setHeader('Content-Length', body.length);
1111
res.end(body);
@@ -29,13 +29,21 @@ app.get('/ball', function(req, res){
2929

3030
var pos = Math.floor((Math.random()*10)+1);
3131

32-
var body = 'magicnodeball : { response : \'' + choices[pos-1] + '\'}';
33-
res.setHeader('Content-Type', 'application/json');
34-
res.setHeader('Content-Length', body.length);
35-
res.end(body);
32+
// var body = 'magicnodeball : { response : \'' + choices[pos-1] + '\'}';
33+
34+
var rval = {};
35+
rval.magicnodeball = {};
36+
rval.magicnodeball.reponse = choices[pos-1];
37+
38+
39+
// res.setHeader('Content-Type', 'application/json');
40+
// res.setHeader('Content-Length', body.length);
41+
// res.end(body);
42+
43+
res.json(rval);
3644

3745
});
3846

39-
app.listen(process.env.PORT || 80);
40-
console.log('Listening on port ' + process.env.PORT || 80);
47+
app.listen(process.env.PORT || 2000);
48+
console.log('Listening on port ' + process.env.PORT || 2000);
4149

0 commit comments

Comments
 (0)