Code Monkey home page Code Monkey logo

runfaas's Introduction

runfaas

Simple "function as a service" server, with authentication.

Currently, this project is WIP: I'm converting the authorization middleware to OpenIDConnect

Install

git clone https://github.com/nkoster/runfaas
cd runfaas
npm i
mkdir functions
echo 'ACCESS_TOKEN_SECRET=MyBigSecret' >>.env
echo 'ADMIN_USER=admin' >>.env
echo 'ADMIN_PASSWORD=AnotherSecret' >>.env
node server.js

"MyBigSecret" comes from your authentication endpoint.

The server will detect changes inside the functions/ directory, and will reload whenever new functions are added or when old functions are removed.

If you want, you can disable the authentication part by adding the following line to your .env file:

AUTHENTICATION=false

In case you want to use a different path for your functions base directory, you can also specify that in the .env file:

FUNCTIONS_PATH=/faas/api/functions

Deploy a FaaS function

Make or copy a directory inside the functions/ directory. The name of that directory will be name of the function, and also part of the name for the API endpoint. Inside the function name directory should live an index.js file with a layout like this:

module.exports = (body, res) => {
  const { name } = body
  res.send({ message: `your name is ${name}` })
}

body contains the POST data and res an express response object.

Example Function

Here is an example for a function named hellofaas, with a dependency pg, which is a nodejs postgresql client library.

mkdir functions/hellofaas
cd functions/hellofaas
npm init -y
npm i pg
cat > index.js << DUDE
module.exports = (body, res) => {
  const pg = require('pg')
  const { name } = body
  res.send({ message: `${name}, pg is at host ${pg.defaults.host}` })
}
DUDE

Function hellofaas is now available for authenticated POST requests at endpoint http://localhost:3030/function/hellofaas or for unauthenticated POST requests in case you have disabled authentication.

Admin Page

At http://localhost:3030/ lives an "admin" page where all invocations (and catched errors) are logged with counter and response time. You need to set and use the ADMIN_USER and ADMIN_PASSWORD in the .env to access the "admin" page.

To do: extend the admin page.

runfaas's People

Contributors

nkoster avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.