An experiment to build a serverless setup using node.js.
The repository and queue are implemented using Pouchdb, but Couchdb will work as well.
There are 4 options to get this running:
git clone
this repository and runnpm install
followed bynpm start
docker run -d -p 8080:8080 seriousme/node-dash
- use the
docker-compose
file in the docker folder - use
kubectl create -f https://raw.githubusercontent.com/seriousme/node-dash/master/k8/node-dash.yaml
to create a deployment on a Kubernetes Installation.
Once it runs you can send your browser to http://<your host>:8080/ which will show you a web interface, on Kubernetes kubectl describe service apiserver
will show the IP/port.
Alternatively you can use any REST client (e.g. CURL/Postman/etc) to talk to the API server
The following endpoints are supported:
curl -X GET "http://localhost:8080/dash/requests"
curl -X GET "http://localhost:8080/dash/requests/:requestid"
An example:
curl -X GET "http://localhost:8080/myactions/sum?a=1&b=2"
An example:
curl -X GET "http://localhost:8080/myactions/sum?a=1&b=2&sync"
curl -X GET "http://localhost:8080/dash/actions"
curl -X GET "http://localhost:8080/dash/actions/:actionid"
An example:
curl -X PUT -H "Content-Type: application/json" -d '{
"_id": "/myactions/min",
"code": "function main(params){ return { \"min\": Number(params.a) - Number(params.b)};}"
}' "http://localhost:8080/dash/actions/%2fmyactions%2fmin"
An example:
curl -X PUT -H "Content-Type: application/json" -d '{
"_id": "/myactions/min",
"code": "function main(params){ return { \"min\": Number(params.a) - Number(params.b)};}",
"_rev": "1-dadb9a995a83675dea6954a1515e08bb"
}' "http://localhost:8080/dash/actions/%2fmyactions%2fmin"
Its an experiment, so don't use this in production unless you know what you are doing ! E.g. isolation between actioncode and the framework is based on node VM functionality which offers some protection but is not bulletproof against hostile actions !
A better, and more elaborate, approach would be to inject the action code into a docker container and then send the requests to that container. If the container is then idle for say 5 minutes it can be shut.