File tree Expand file tree Collapse file tree 2 files changed +30
-12
lines changed
Expand file tree Collapse file tree 2 files changed +30
-12
lines changed Original file line number Diff line number Diff line change @@ -228,18 +228,28 @@ It will be passed as an argument to your function when it receives a request.
228228Note that your function must use the `cloudevent`-style function signature:
229229
230230```js
231- exports.helloCloudEvents = (cloudevent) => {
231+ const functions = require(' @google - cloud / functions - framework ' );
232+
233+ functions.cloudEvent(' helloCloudEvents ' , (cloudevent) => {
232234 console.log(cloudevent.specversion);
233235 console.log(cloudevent.type);
234236 console.log(cloudevent.source);
235237 console.log(cloudevent.subject);
236238 console.log(cloudevent.id);
237239 console.log(cloudevent.time);
238240 console.log(cloudevent.datacontenttype);
239- };
241+ }) ;
240242```
241243
242- To enable CloudEvents, set the signature type to `cloudevent`. By default, the HTTP signature will be used and automatic event unmarshalling will be disabled.
244+ To enable the CloudEvent functions, you must list the Functions Framework as a dependency in your `package.json`:
245+
246+ ```json
247+ {
248+ "dependencies": {
249+ "@google-cloud/functions-framework": "~2.0.0-beta.1"
250+ }
251+ }
252+ ```
243253
244254Learn how to use CloudEvents in this [guide](docs/cloudevents.md).
245255
Original file line number Diff line number Diff line change @@ -7,27 +7,35 @@ This guide shows you how to use the Functions Framework for local testing with:
77
88## Local Testing of CloudEvents
99
10- In your ` package.json ` , specify ` --signature-type=cloudevent" ` for the ` functions-framework ` :
10+ Install ` @google-cloud/functions-framework ` and list it as a dependency in your ` package.json ` :
1111
12- ``` sh
13- {
14- " scripts" : {
15- " start" : " functions-framework --target=helloCloudEvents --signature-type=cloudevent"
16- }
17- }
12+ ```
13+ npm install --save @google-cloud/functions-framework
1814```
1915
20- Create an ` index.js ` file:
16+ Create an ` index.js ` file and declare your function :
2117
2218``` js
23- exports .helloCloudEvents = (cloudevent ) => {
19+ const functions = require (' @google-cloud/functions-framework' );
20+
21+ functions .cloudEvent (' helloCloudEvents' , (cloudevent ) => {
2422 console .log (cloudevent .specversion );
2523 console .log (cloudevent .type );
2624 console .log (cloudevent .source );
2725 console .log (cloudevent .subject );
2826 console .log (cloudevent .id );
2927 console .log (cloudevent .time );
3028 console .log (cloudevent .datacontenttype );
29+ });
30+ ```
31+
32+ Add a ` package.json ` script to start the Functions Framework and pass the name of your function as the ` target ` .
33+
34+ ``` sh
35+ {
36+ " scripts" : {
37+ " start" : " functions-framework --target=helloCloudEvents"
38+ }
3139}
3240```
3341
You can’t perform that action at this time.
0 commit comments