Skip to content

Commit

Permalink
Merge pull request #11 from shyaminayesh/prod
Browse files Browse the repository at this point in the history
Bridge can handle POST & query strings ( resolve #9 & #10 )
  • Loading branch information
shyaminayesh committed May 14, 2019
2 parents c791842 + 9d29701 commit 7434c04
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
26 changes: 22 additions & 4 deletions lib/Bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,28 @@ class Bridge {
* make things simple to handle
*/
call(req, callback) {
request('http://unix:' + this.socket + ':' + req.node, {
method: req.method,
headers: { 'Content-Type': 'application/json', host: 'http' }
}, (error, response) => {

// PROPS
let node = "http://unix" + this.socket + ":" + req.node
let payload = {}

// QUERY PARAMS
if ( req.query !== undefined ) {
node = node + "?" + Object.keys(req.query).map(key => key + '=' + req.query[key]).join('&')
}

if ( req.method === 'GET' ) {
payload.method = req.method
payload.headers = { 'Content-Type': 'application/json', host: 'http' }
}

if ( req.method === 'POST' ) {
payload.method = req.method
payload.headers = { 'Content-Type': 'application/json', host: 'http' }
payload.body = JSON.stringify(req.params)
}

request(node, payload, (error, response) => {
callback(error, response)
})
}
Expand Down
17 changes: 17 additions & 0 deletions lib/Containers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { Bridge } = require("./Bridge")


class Containers extends Bridge {

create(params, query) {
return new Promise((resolve, reject) => {
this.call({ node: '/containers/create', method: 'POST', params: params, query: query }, (err, res) => {
resolve(res)
})
})
}

}


exports.Containers = Containers
2 changes: 2 additions & 0 deletions lib/Dockernize.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { Engine } = require("./Engine")
const { Images } = require("./Images")
const { Containers } = require("./Containers")

class Dockernize {
constructor(params) {
this.engine = new Engine(params)
this.images = new Images(params)
this.containers = new Containers(params)
}
}

Expand Down

0 comments on commit 7434c04

Please sign in to comment.