mirror of
https://github.com/openfaas/faas.git
synced 2025-06-21 22:33:23 +00:00
Add NodeBase function concept
This commit is contained in:
29
sample-functions/NodeBaseFunction/faas_index.js
Normal file
29
sample-functions/NodeBaseFunction/faas_index.js
Normal file
@ -0,0 +1,29 @@
|
||||
"use strict"
|
||||
|
||||
let getStdin = require('get-stdin');
|
||||
|
||||
let handler = require('./handler');
|
||||
|
||||
getStdin().then(val => {
|
||||
|
||||
let req;
|
||||
if(process.env.json) {
|
||||
req = JSON.parse(val);
|
||||
} else {
|
||||
req = val
|
||||
}
|
||||
|
||||
handler(req, (err, res) => {
|
||||
if(err) {
|
||||
return console.error(err);
|
||||
}
|
||||
|
||||
if(process.env.json) {
|
||||
console.log(JSON.stringify(res));
|
||||
} else {
|
||||
console.log(res);
|
||||
}
|
||||
});
|
||||
}).catch(e => {
|
||||
console.error(e.stack);
|
||||
});
|
Reference in New Issue
Block a user