You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This repo contains a sample application that shows how OpenFaaS can be used to build a basic function editor that let's users edit, deploy and invoke custom code from the browser.
4
+
5
+
The sample app consists of two parts. A frontend implemented as a single page [React](https://react.dev/) application and [Express](https://expressjs.com/) server for the backend API. Users can edit a Node.js function in the UI using a code editor. Clicking the `Publish and Deploy` button deploys the function to OpenFaaS. Once deployed the `Test Function` page can be used to invoke the function, inspect responses and view the function logs.
6
+
7
+
It sample app is a basic implementation of the use case described in the our blog post: [Integrate FaaS Capabilities into Your Platform with OpenFaaS](https://www.openfaas.com/blog/add-a-faas-capability/)
8
+
9
+

10
+
11
+
## How it works
12
+
13
+
The application uses readily available OpenFaaS APIs to take user-supplied source-code, produce an OpenFaaS function image and deploy it to OpenFaaS to get a custom HTTP endpoint.
14
+
15
+
OpenFaaS components used by the sample application:
API for managing and invoking functions, secrets and namespaces.
26
+
27
+
The OpenFaaS REST API has endpoints to create and manage tenant namespaces, to deploy new functions, list and query existing ones, invoke them and query function logs.
28
+
29
+
**Overview**
30
+
31
+
1. User supplied source-code from the editor is send to the backends `/api/publish` endpoint.
32
+
2. The publish endpoint prepares the build context using a function template and invokes the [OpenFaaS Function Builder REST API](https://docs.openfaas.com/openfaas-pro/builder/).
33
+
3. The OpenFaaS function builder builds the container image for the function and published it to the configured registry.
34
+
4. After the function has been published the `/api/publish` endpoint is called. The backend server calls the [OpenFaaS API](https://docs.openfaas.com/reference/rest-api/) to deploy the function.
35
+
5. The function is ready to be invoked over HTTP.
36
+
37
+
A couple of additional OpenFaaS API endpoints are exposed through the backed server that allow users to invoke the function and inspect logs in the UI:
38
+
39
+
-`/api/invoke` - Proxies the functions HTTP endpoint.
40
+
-`/api/logs` - Uses the [OpenFaaS APIs logs endpoint](https://docs.openfaas.com/reference/rest-api/#logs) to get the logs for the function.
41
+
42
+
> Note: Authentication for the backend API as this is out of scope for this examples. Keep in mind the for a production ready app some form of authentication should be added to protect the API endpoint.
43
+
44
+
## Quick start
45
+
46
+
Run the sample application locally.
47
+
48
+
### Prerequisites
49
+
50
+
51
+
A Kubernetes cluster with OpenFaaS and the [OpenFaaS Function Builder API](https://docs.openfaas.com/openfaas-pro/builder/).
52
+
53
+
> The Function Builder API provides a simple REST API to create your functions from source code. See [Function Builder API docs](https://docs.openfaas.com/openfaas-pro/builder/) for installation instructions.
54
+
55
+
You will need a recent version of [Node.js](https://nodejs.org/en) to run the sample app locally.
56
+
57
+
### Run the app
58
+
59
+
Install node_modules:
60
+
61
+
```sh
62
+
cd client
63
+
npm install
64
+
```
65
+
66
+
**Run the API server**
67
+
68
+
Configuration parameters:
69
+
70
+
-`IMAGE_PREFIX` - Image prefix used for pushing the images, e.g. `docker.io/openfaas`. Make sur your function builder [has the correct permissions](https://github.com/openfaas/faas-netes/tree/master/chart/pro-builder#registry-authentication) to push to this registry.
71
+
-`BUILDER_URL` - URl of the function builder API (default: http://127.0.0.1:8081)
72
+
-`BUILDER_PAYLOAD_SECRET` - Path the file containing the HMAC signing secret created during the installation of the function builder. (default: "./builder/payload.txt")
73
+
-`GATEWAY_URL` - URL of the OpenFaaS Gateway (default: http://127.0.0.1:8080)
74
+
-`BASIC_AUTH_SECRET` - Basic auth secret to authenticate with the OpenFaaS Gateway (default: "./secrets/basic-auth-password.txt")
0 commit comments