Skip to content

Commit 292ab4b

Browse files
authored
✨ feat(knative/node): add http trigger sample (#79)
Signed-off-by: Haili Zhang <haili.zhang@outlook.com>
1 parent 1cf4c66 commit 292ab4b

3 files changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
apiVersion: core.openfunction.io/v1beta1
2+
kind: Function
3+
metadata:
4+
name: sample-node-http-trigger
5+
spec:
6+
version: v2.0.0
7+
image: your-docker-registry/image:tag
8+
# imageCredentials:
9+
# name: your-docker-registry-secret
10+
# build:
11+
# builder: openfunction/builder-node:v2-16.13
12+
# env:
13+
# FUNC_NAME: tryKnative
14+
# srcRepo:
15+
# url: https://github.com/OpenFunction/samples.git
16+
# sourceSubPath: functions/async/mqtt-io-node
17+
# revision: main
18+
# app port default to "8080"
19+
# port: 8080
20+
serving:
21+
# default to knative
22+
runtime: knative
23+
scaleOptions:
24+
minReplicas: 0
25+
maxReplicas: 2
26+
annotations:
27+
# Dapr annotations: https://docs.dapr.io/reference/arguments-annotations-overview/
28+
# default to "info"
29+
dapr.io/log-level: debug
30+
# default to "true"
31+
dapr.io/log-as-json: 'false'
32+
template:
33+
containers:
34+
- name: function
35+
imagePullPolicy: Always
36+
params:
37+
# default to FUNC_NAME value
38+
FUNCTION_TARGET: tryKnativeAsync
39+
# default to http
40+
FUNCTION_SIGNATURE_TYPE: openfunction
41+
DEBUG: common:*,ofn:*
42+
outputs:
43+
- name: mqtt-output
44+
component: mqtt-out
45+
operation: create
46+
bindings:
47+
# Dapr MQTT Binding: https://docs.dapr.io/reference/components-reference/supported-bindings/mqtt/
48+
mqtt-out:
49+
type: bindings.mqtt
50+
version: v1
51+
metadata:
52+
- name: consumerID
53+
value: '{uuid}'
54+
- name: url
55+
value: tcp://admin:public@emqx:1883
56+
- name: topic
57+
value: out
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const tryKnative = (req, res) => {
2+
res.send(`Hello, ${req.query.u || 'World'}!`);
3+
};
4+
5+
export const tryKnativeAsync = async (ctx, data) => {
6+
console.log('Data received: %o', data);
7+
await ctx.send(data);
8+
9+
// Optional to send ANY data back as HTTP response
10+
// Request data is also accessible via "ctx.req"
11+
// ctx.res.send(ctx.req.query);
12+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"main": "index.mjs",
3+
"scripts": {
4+
"start": "functions-framework --target=tryKnative"
5+
},
6+
"dependencies": {
7+
"@openfunction/functions-framework": "^0.5.0"
8+
}
9+
}

0 commit comments

Comments
 (0)