- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
Latest commit
30 lines (28 loc) · 715 Bytes
/
Copy pathserver.js
File metadata and controls
30 lines (28 loc) · 715 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
'use strict';
constHapi=require('hapi');
constserver=newHapi.Server();
consthttp=require('http');
constStream=require('stream');
server.connection({port: 3000,host: '127.0.0.1'});
server.route({
method: 'GET',
path: '/',
handler: function(request,reply){
letstream=newStream.PassThrough();
setInterval(function(){
http.get("http://randomword.setgetgo.com/get.php",function(res){
res.setEncoding('utf8');
res.on('data',function(word){
stream.write(JSON.stringify({message: word}));
});
});
},500);
reply(stream);
}
});
server.start((err)=>{
if(err){
throwerr;
}
process.send({message: "Ready"});
});