Code files

This commit is contained in:
Akhil
2017-07-31 11:33:31 +05:30
parent 073a63ebdd
commit b9ae409ec0
801 changed files with 17535 additions and 0 deletions
@@ -0,0 +1,7 @@
'use strict'
const wiring = require('./wiring')
const service = require('./service')()
wiring(service)
@@ -0,0 +1,18 @@
{
"name": "adderservice",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "tap test"
},
"keywords": [],
"author": "Peter Elger",
"license": "ISC",
"dependencies": {
"restify": "^4.3.0"
},
"devDependencies": {
"tap": "^10.3.1"
}
}
@@ -0,0 +1,13 @@
'use strict'
module.exports = service
function service () {
function add (args, cb) {
const {first, second} = args
const result = (parseInt(first, 10) + parseInt(second, 10))
cb(null, {result: result.toString()})
}
return { add }
}
@@ -0,0 +1,13 @@
'use strict'
const {test} = require('tap')
const service = require('../service')()
test('test add', (t) => {
t.plan(2)
service.add({first: 1, second: 2}, (err, answer) => {
t.error(err)
t.same(answer, {result: 3})
})
})
@@ -0,0 +1,27 @@
'use strict'
const restify = require('restify')
const { ADDERSERVICE_SERVICE_PORT } = process.env
module.exports = wiring
function wiring (service) {
const server = restify.createServer()
server.get('/add/:first/:second', (req, res, next) => {
service.add(req.params, (err, result) => {
if (err) {
res.send(err)
next()
return
}
res.send(200, result)
next()
})
})
server.listen(ADDERSERVICE_SERVICE_PORT, '0.0.0.0', () => {
console.log('%s listening at %s', server.name, server.url)
})
}