|
1 | 1 | /* eslint-disable */
|
2 | 2 |
|
3 | 3 | const express = require("express");
|
4 |
| -const { Receiver, DiscoveryService } = require("cloudevents"); |
| 4 | +const { Receiver } = require("cloudevents"); |
5 | 5 | const app = express();
|
6 | 6 | const bodyParser = require("body-parser");
|
7 | 7 | app.use(bodyParser.json());
|
8 | 8 |
|
9 |
| -DiscoveryService.registerService({ |
10 |
| - url: "https://example.com/services/widgetService", |
11 |
| - name: "com.example.services.widgetService", |
12 |
| - specversions: ["1.0"], |
13 |
| - subscriptionurl: "https://events.example.com", |
14 |
| - protocols: ["HTTP"], |
15 |
| - types: [ |
16 |
| - { |
17 |
| - type: "com.example.widget.create", |
18 |
| - type: "com.example.widget.delete", |
19 |
| - }, |
20 |
| - ], |
21 |
| -}); |
22 |
| -DiscoveryService.registerService({ |
23 |
| - url: "https://example.com/services/catService", |
24 |
| - name: "com.example.services.catService", |
25 |
| - specversions: ["1.0"], |
26 |
| - subscriptionurl: "https://cats.example.com", |
27 |
| - protocols: ["HTTP"], |
28 |
| - types: [ |
29 |
| - { |
30 |
| - type: "com.example.cats.buy", |
31 |
| - type: "com.example.cats.adopt", |
32 |
| - type: "com.example.cats.feed", |
33 |
| - type: "com.example.cats.give", |
34 |
| - // Just to play with discovery service |
35 |
| - type: "com.example.widget.create", |
36 |
| - }, |
37 |
| - ], |
38 |
| -}); |
39 |
| - |
40 |
| -DiscoveryService.express(app); |
41 |
| -// Create a anonymous mapping of cloud events for example |
42 |
| -DiscoveryService.express(app, "/anonymous", (name, type, req) => { |
43 |
| - // A true life example would have only one call to express and check req for permission |
44 |
| - // Only give access to the catService and widgetCreate if anonymous |
45 |
| - return name === "com.example.widget.create" || name === "com.example.services.catService"; |
46 |
| -}); |
47 |
| - |
48 | 9 | app.post("/", (req, res) => {
|
49 | 10 | console.log("HEADERS", req.headers);
|
50 | 11 | console.log("BODY", req.body);
|
|
0 commit comments