@jcbuisson/express-x 1.7.4 → 1.7.6
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/package.json +1 -1
- package/src/server.mjs +9 -8
package/package.json
CHANGED
package/src/server.mjs
CHANGED
|
@@ -6,11 +6,12 @@ import express from 'express'
|
|
|
6
6
|
/*
|
|
7
7
|
* Enhance `app` express application with services and real-time features
|
|
8
8
|
*/
|
|
9
|
-
export function expressX(prisma,
|
|
9
|
+
export function expressX(prisma, config) {
|
|
10
10
|
|
|
11
11
|
const app = express()
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
// websocket transport by default
|
|
14
|
+
if (config.WS_TRANSPORT == undefined) config.WS_TRANSPORT = true
|
|
14
15
|
|
|
15
16
|
const services = {}
|
|
16
17
|
let appHooks = []
|
|
@@ -45,7 +46,7 @@ export function expressX(prisma, options = {}) {
|
|
|
45
46
|
try {
|
|
46
47
|
await prisma.Connection.delete({ where: { id }})
|
|
47
48
|
} catch(err) {
|
|
48
|
-
//
|
|
49
|
+
// in case it would no longer exist
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
|
|
@@ -120,7 +121,7 @@ export function expressX(prisma, options = {}) {
|
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
// publish event (websocket transport)
|
|
123
|
-
if (
|
|
124
|
+
if (config.WS_TRANSPORT && service.publishFunction) {
|
|
124
125
|
const channelNames = await service.publishFunction(result, app)
|
|
125
126
|
app.log('verbose', `publish channels ${service.name} ${methodName} ${channelNames}`)
|
|
126
127
|
const connections = await app.prisma.Connection.findMany({})
|
|
@@ -311,7 +312,7 @@ export function expressX(prisma, options = {}) {
|
|
|
311
312
|
*/
|
|
312
313
|
const server = new http.Server(app)
|
|
313
314
|
|
|
314
|
-
if (
|
|
315
|
+
if (config.WS_TRANSPORT) {
|
|
315
316
|
/*
|
|
316
317
|
* Add websocket transport
|
|
317
318
|
*/
|
|
@@ -334,7 +335,7 @@ export function expressX(prisma, options = {}) {
|
|
|
334
335
|
socket.on('disconnect', () => {
|
|
335
336
|
app.log('verbose', `Client disconnected ${connection.id}`)
|
|
336
337
|
|
|
337
|
-
// remove connection record after
|
|
338
|
+
// remove connection record after expiration delay, if it still exists
|
|
338
339
|
setTimeout(async () => {
|
|
339
340
|
const connectionId = connection.id
|
|
340
341
|
// check if connection still exists
|
|
@@ -343,7 +344,7 @@ export function expressX(prisma, options = {}) {
|
|
|
343
344
|
app.log('verbose', `Delete connection ${connectionId}`)
|
|
344
345
|
await deleteConnection(connectionId)
|
|
345
346
|
}
|
|
346
|
-
},
|
|
347
|
+
}, config.SESSION_EXPIRE_DELAY || 24*60*60000)
|
|
347
348
|
})
|
|
348
349
|
|
|
349
350
|
|
|
@@ -455,7 +456,7 @@ export function expressX(prisma, options = {}) {
|
|
|
455
456
|
// enhance `app` with objects and methods
|
|
456
457
|
return Object.assign(app, {
|
|
457
458
|
prisma,
|
|
458
|
-
|
|
459
|
+
config,
|
|
459
460
|
getSocket, setSocket,
|
|
460
461
|
createDatabaseService,
|
|
461
462
|
createService,
|