11express = require ( 'express' ) ;
22var 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