corebasic 1.0.68 → 1.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +3 -1
- package/libs/features.js +3 -0
- package/libs/messaging.js +11 -7
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import * as Utils from './libs/utils.js'
|
|
|
7
7
|
import * as Session from './libs/session.js'
|
|
8
8
|
import * as Auth from './libs/auth.js'
|
|
9
9
|
import * as Features from './libs/features.js'
|
|
10
|
+
import * as Messaging from './libs/messaging.js'
|
|
10
11
|
|
|
11
12
|
export {
|
|
12
13
|
Elabase,
|
|
@@ -15,5 +16,6 @@ export {
|
|
|
15
16
|
Utils,
|
|
16
17
|
Session,
|
|
17
18
|
Auth,
|
|
18
|
-
Features
|
|
19
|
+
Features,
|
|
20
|
+
Messaging
|
|
19
21
|
}
|
package/libs/features.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as Elabase from './elabase.js'
|
|
2
2
|
import * as Kafka from './kafka.js'
|
|
3
3
|
import * as Utils from './utils.js'
|
|
4
|
+
import * as Messaging from './messaging.js'
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
let features = {}
|
|
@@ -92,6 +93,8 @@ export const start = async (app, url, file) => {
|
|
|
92
93
|
res.status(500).json({ message: "Failed to retreive data" })
|
|
93
94
|
}
|
|
94
95
|
})
|
|
96
|
+
|
|
97
|
+
try { await Messaging.start(app) } catch { console.log('Messaging failed to start. Maybe missing redis') }
|
|
95
98
|
}
|
|
96
99
|
|
|
97
100
|
const commandAction = async (req, res, topic) => {
|
package/libs/messaging.js
CHANGED
|
@@ -3,12 +3,8 @@ import axios from 'axios'
|
|
|
3
3
|
import { createClient } from 'redis';
|
|
4
4
|
|
|
5
5
|
// url: 'redis://alice:foobared@localhost:6380'
|
|
6
|
-
|
|
7
|
-
await consumer.connect();
|
|
8
|
-
const publisher = createClient({ url: 'redis://localhost:6380' });
|
|
9
|
-
await publisher.connect();
|
|
6
|
+
let consumer, publisher
|
|
10
7
|
|
|
11
|
-
consumer.on('error', err => console.log('Redis Client Error', err));
|
|
12
8
|
|
|
13
9
|
|
|
14
10
|
let users_pool = {
|
|
@@ -27,7 +23,14 @@ async function connect({user,req,res}) {
|
|
|
27
23
|
});
|
|
28
24
|
}
|
|
29
25
|
|
|
30
|
-
export function start(app) {
|
|
26
|
+
export async function start(app) {
|
|
27
|
+
consumer = createClient({ url: 'redis://localhost:6380' });
|
|
28
|
+
await consumer.connect();
|
|
29
|
+
publisher = createClient({ url: 'redis://localhost:6380' });
|
|
30
|
+
await publisher.connect();
|
|
31
|
+
|
|
32
|
+
consumer.on('error', err => console.log('Redis Client Error', err));
|
|
33
|
+
|
|
31
34
|
app.get('/messages/:user', async (req, res) => {
|
|
32
35
|
await connect({user: req.params.user, req, res})
|
|
33
36
|
req.on("close", async () => await disconnect(req.params.user)) // request closed unexpectedly
|
|
@@ -37,7 +40,8 @@ export function start(app) {
|
|
|
37
40
|
|
|
38
41
|
|
|
39
42
|
export async function publish(channel, message) {
|
|
40
|
-
|
|
43
|
+
if (publisher)
|
|
44
|
+
await publisher.publish(channel, typeof message === "object" ? JSON.stringify(message) : message);
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
|