-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (30 loc) · 1.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const { CloudEvent } = require('cloudevents');
/**
* Your CloudEvent handling function, invoked with each request.
* This example function logs its input, and responds with a CloudEvent
* which echoes the incoming event data
*
* It can be invoked with 'func invoke'
* It can be tested with 'npm test'
*
* @param {Context} context a context object.
* @param {object} context.body the request body if any
* @param {object} context.query the query string deserialzed as an object, if any
* @param {object} context.log logging object with methods for 'info', 'warn', 'error', etc.
* @param {object} context.headers the HTTP request headers
* @param {string} context.method the HTTP request method
* @param {string} context.httpVersion the HTTP protocol version
* See: https://github.com/knative/func/blob/main/docs/function-developers/nodejs.md#the-context-object
* @param {CloudEvent} event the CloudEvent
*/
const handle = async (context, event) => {
// YOUR CODE HERE
context.log.info("context", context);
context.log.info("event", event);
return new CloudEvent({
source: 'event.handler',
type: 'echo',
data: event.data
});
};
module.exports = { handle };