This repository has been archived by the owner on Feb 4, 2020. It is now read-only.
forked from austinfrey/node-openfaas
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
3,216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const BbPromise = require('bluebird'); | ||
const got = require('got'); | ||
|
||
const compose = baseUrl => { | ||
return (initial, funcs) => { | ||
const functions = funcs.map(func => { | ||
return data => { | ||
const options = { | ||
method: 'POST', | ||
body: data | ||
}; | ||
|
||
const funcUrl = baseUrl + path.join('/function', func); | ||
return got(funcUrl, options) | ||
.then(res => BbPromise.resolve(res)) | ||
.catch(err => BbPromise.reject(err)); | ||
}; | ||
}); | ||
|
||
return functions.reduce( | ||
(current, f) => { | ||
return current.then(x => f(x.body)); | ||
}, | ||
new BbPromise(resolve => resolve(initial)) | ||
); | ||
}; | ||
}; | ||
|
||
module.exports = compose; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
const got = require('got'); | ||
|
||
const deploy = gateway => { | ||
const url = gateway; | ||
|
||
return (name, network, image) => { | ||
const deployPath = '/system/functions'; | ||
const options = { | ||
method: 'POST', | ||
json: true, | ||
body: { | ||
service: name, | ||
network, | ||
image | ||
} | ||
}; | ||
|
||
return got(url + deployPath, options); | ||
}; | ||
}; | ||
|
||
module.exports = deploy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
const deploy = require('./deploy'); | ||
const remove = require('./remove'); | ||
const invoke = require('./invoke'); | ||
const compose = require('./compose'); | ||
|
||
const faas = url => ({ | ||
deploy: deploy(url), | ||
remove: remove(url), | ||
invoke: invoke(url), | ||
compose: compose(url) | ||
}); | ||
|
||
module.exports = faas; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const got = require('got'); | ||
|
||
const invoke = gateway => { | ||
const url = gateway; | ||
|
||
return (name, data) => { | ||
const funcPath = path.join('/function', name); | ||
const options = { | ||
method: 'POST', | ||
json: true | ||
}; | ||
|
||
if (data) { | ||
options.body = data; | ||
} | ||
|
||
return got(url + funcPath, options); | ||
}; | ||
}; | ||
|
||
module.exports = invoke; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const got = require('got'); | ||
|
||
const remove = gateway => { | ||
const url = gateway; | ||
|
||
return name => { | ||
const options = { | ||
method: 'DELETE', | ||
json: true, | ||
body: { | ||
functionName: name | ||
} | ||
}; | ||
|
||
return got(url + '/system/functions', options); | ||
}; | ||
}; | ||
|
||
module.exports = remove; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const Faas = require('./faas'); | ||
|
||
const faas = Faas('http://localhost:8080'); | ||
|
||
faas.deploy( | ||
'yolo', | ||
'func_functions', | ||
'hello-serverless' | ||
) | ||
.then(x => console.log(x)) | ||
.catch(err => console.log(err)); | ||
|
Oops, something went wrong.