-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (35 loc) · 915 Bytes
/
index.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
const Hapi = require('hapi')
const server = new Hapi.Server()
let request = require('request')
server.connection({port: 8080})
server.route({
method: 'GET',
path: '/dates/{timestamp}',
handler: (req, reply) => {
const utcEndpoint = `http://utcdate-service:3001/utcdate/${req.params.timestamp}`
const isoEndpoint = `http://isodate-service:3000/isodate/${req.params.timestamp}`
request(utcEndpoint, (err, response, utcBody) => {
if (err) {
console.log(err)
return
}
request(isoEndpoint, (err, response, isoBody) => {
if (err) {
console.log(err)
return
}
reply({
utcDate: JSON.parse(utcBody).date,
isoDate: JSON.parse(isoBody).date,
version: "2.0"
})
})
})
}
})
server.start((err) => {
if (err) {
throw err
}
console.log('aggregator started on port 8080')
})