-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent-subscriber-app.js
More file actions
52 lines (41 loc) · 1.19 KB
/
Copy pathevent-subscriber-app.js
File metadata and controls
52 lines (41 loc) · 1.19 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* LOWCODE-DATA-APP / copyright 2024 by ma-ha https://github.com/ma-ha / MIT License */
const axios = require( 'axios' )
const express = require('express')
const bodyParser = require( 'body-parser' )
const url = 'http://localhost:8888/app/event/subscribe'
const port = 3001
init()
async function init() {
await subscribeEvents()
await starEventReceiver( processEvent )
}
async function processEvent(req, res) {
console.log( req.body )
res.send( )
}
async function subscribeEvents() {
const res = await axios.post( url, {
name: 'test-app',
webHook : 'http://localhost:3001/event',
// filter: {
// op: "dta.add",
// data: { col: 'blue' }
// }
},
{
headers: {
'app-id': '5a095719-cfbe-49d3-8927-a55da94221ed',
'app-secret': '5a095719-cfbe-49d3-8927-a55da94221ed'
}
})
console.log( res.status, res.data )
}
async function starEventReceiver( processEventFunction) {
const app = express()
app.use( bodyParser.urlencoded({ limit: "20mb", extended: false }) )
app.use( bodyParser.json({ limit: "20mb" }) )
app.post( '/event', processEventFunction )
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
}