diff --git a/sample-functions/nodeinfo-http/.gitignore b/sample-functions/nodeinfo-http/.gitignore new file mode 100644 index 00000000..942d901b --- /dev/null +++ b/sample-functions/nodeinfo-http/.gitignore @@ -0,0 +1,2 @@ +template +build diff --git a/sample-functions/nodeinfo-http/handler.js b/sample-functions/nodeinfo-http/handler.js new file mode 100644 index 00000000..c59fef91 --- /dev/null +++ b/sample-functions/nodeinfo-http/handler.js @@ -0,0 +1,32 @@ +'use strict' +let os = require('os'); +let fs = require('fs'); +const fsPromises = fs.promises +let util = require('util'); + +module.exports = async (event, context) => { + let content = event.body; + + let res = await info(content) + return context + .status(200) + .succeed(res) +} + +async function info(content, callback) { + let data = await fsPromises.readFile("/etc/hostname", "utf8") + + let val = ""; + val += "Hostname: " + data +"\n"; + val += "Platform: " + os.platform()+"\n"; + val += "Arch: " + os.arch() + "\n"; + val += "CPU count: " + os.cpus().length+ "\n"; + + val += "Uptime: " + os.uptime()+ "\n"; + + if (content && content.length && content.indexOf("verbose") > -1) { + val += util.inspect(os.cpus()) + "\n"; + val += util.inspect(os.networkInterfaces())+ "\n" + } + return val +}; diff --git a/sample-functions/nodeinfo-http/package.json b/sample-functions/nodeinfo-http/package.json new file mode 100644 index 00000000..a3c013b0 --- /dev/null +++ b/sample-functions/nodeinfo-http/package.json @@ -0,0 +1,12 @@ +{ + "name": "openfaas-function", + "version": "1.0.0", + "description": "OpenFaaS Function", + "main": "handler.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 0" + }, + "keywords": [], + "author": "OpenFaaS Ltd", + "license": "MIT" +} diff --git a/sample-functions/stack.yml b/sample-functions/stack.yml index 60e62f5d..5257fec9 100644 --- a/sample-functions/stack.yml +++ b/sample-functions/stack.yml @@ -90,3 +90,11 @@ functions: lang: go handler: ./business-strategy-generator image: functions/business-strategy-generator:0.13.0 + nodeinfo-http: + lang: node12 + handler: ./nodeinfo-http + image: functions/nodeinfo-http:latest + environment: + RAW_BODY: true + +