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
Upon running ```sh npm start ```, you'll see the function is still being served at http://localhost:8080/. However it is no longer accessible via GET requests from the browser. Instead, send a POST request where the request body conforms to the API defined by [push subscriptions](https://cloud.google.com/pubsub/docs/push).
56
-
57
-
### Submitting POST request to simulating a pubsub message
58
-
59
-
Create mockPubsub.json file with the following contents:
The file can be in any folder on your computer. From the terminal, goto the directory where ```mockPubsub.json``` is located, and run the following command assuming your cloud function is hosted locally on port 8080:
74
-
```sh
75
-
curl -d "@mockPubsub.json" -X POST \
76
-
-H "Ce-Type: true" \
77
-
-H "Ce-Specversion: true" \
78
-
-H "Ce-Source: true" \
79
-
-H "Ce-Id: true" \
80
-
-H "Content-Type: application/json" \
81
-
http://localhost:8080
82
-
```
83
-
84
-
> In order to simulate a Cloud Event, you need to add the ```Ce-*``` headers, along with a _truthy_ value, to the request.
85
-
86
-
### Using pubsub emulator
87
-
88
-
Another way to test your cloud function pubsub endpoint is to use the [pubsub emulator](https://cloud.google.com/pubsub/docs/emulator). This allows you to use the pubsub notification from another service to trigger your cloud function.
89
-
90
-
The high level approach is to:
91
-
1. Start the pubsub emulator
92
-
2. Use the pubsub client library to create a subscription and set the pushEndpoint to http://localhost:8080.
93
-
94
-
After that, all notifications to the subscription topic will be pushed to your cloud function.
95
-
96
-
Sample script for creating subscription with pushEndpoint:
0 commit comments