Skip to content
This repository was archived by the owner on Feb 4, 2020. It is now read-only.

Commit d52861b

Browse files
committed
initial commit
Signed-off-by: Austin Frey <[email protected]>
0 parents  commit d52861b

File tree

10 files changed

+3216
-0
lines changed

10 files changed

+3216
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

faas/compose.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const BbPromise = require('bluebird');
5+
const got = require('got');
6+
7+
const compose = baseUrl => {
8+
return (initial, funcs) => {
9+
const functions = funcs.map(func => {
10+
return data => {
11+
const options = {
12+
method: 'POST',
13+
body: data
14+
};
15+
16+
const funcUrl = baseUrl + path.join('/function', func);
17+
return got(funcUrl, options)
18+
.then(res => BbPromise.resolve(res))
19+
.catch(err => BbPromise.reject(err));
20+
};
21+
});
22+
23+
return functions.reduce(
24+
(current, f) => {
25+
return current.then(x => f(x.body));
26+
},
27+
new BbPromise(resolve => resolve(initial))
28+
);
29+
};
30+
};
31+
32+
module.exports = compose;

faas/deploy.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const got = require('got');
4+
5+
const deploy = gateway => {
6+
const url = gateway;
7+
8+
return (name, network, image) => {
9+
const deployPath = '/system/functions';
10+
const options = {
11+
method: 'POST',
12+
json: true,
13+
body: {
14+
service: name,
15+
network,
16+
image
17+
}
18+
};
19+
20+
return got(url + deployPath, options);
21+
};
22+
};
23+
24+
module.exports = deploy;

faas/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const deploy = require('./deploy');
4+
const remove = require('./remove');
5+
const invoke = require('./invoke');
6+
const compose = require('./compose');
7+
8+
const faas = url => ({
9+
deploy: deploy(url),
10+
remove: remove(url),
11+
invoke: invoke(url),
12+
compose: compose(url)
13+
});
14+
15+
module.exports = faas;
16+

faas/invoke.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const got = require('got');
5+
6+
const invoke = gateway => {
7+
const url = gateway;
8+
9+
return (name, data) => {
10+
const funcPath = path.join('/function', name);
11+
const options = {
12+
method: 'POST',
13+
json: true
14+
};
15+
16+
if (data) {
17+
options.body = data;
18+
}
19+
20+
return got(url + funcPath, options);
21+
};
22+
};
23+
24+
module.exports = invoke;

faas/remove.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const got = require('got');
4+
5+
const remove = gateway => {
6+
const url = gateway;
7+
8+
return name => {
9+
const options = {
10+
method: 'DELETE',
11+
json: true,
12+
body: {
13+
functionName: name
14+
}
15+
};
16+
17+
return got(url + '/system/functions', options);
18+
};
19+
};
20+
21+
module.exports = remove;

index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const Faas = require('./faas');
2+
3+
const faas = Faas('http://localhost:8080');
4+
5+
faas.deploy(
6+
'yolo',
7+
'func_functions',
8+
'hello-serverless'
9+
)
10+
.then(x => console.log(x))
11+
.catch(err => console.log(err));
12+

0 commit comments

Comments
 (0)