@jcbuisson/express-x 1.7.6 → 1.7.8
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 +11 -6
package/package.json
CHANGED
package/src/server.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
import
|
|
3
|
-
import { Server } from
|
|
2
|
+
import { createServer } from 'http'
|
|
3
|
+
import { Server } from 'socket.io'
|
|
4
4
|
import express from 'express'
|
|
5
5
|
|
|
6
6
|
/*
|
|
@@ -10,6 +10,9 @@ export function expressX(prisma, config) {
|
|
|
10
10
|
|
|
11
11
|
const app = express()
|
|
12
12
|
|
|
13
|
+
// so that config can be accessed anywhere with app.get('config')
|
|
14
|
+
app.set('config', config)
|
|
15
|
+
|
|
13
16
|
// websocket transport by default
|
|
14
17
|
if (config.WS_TRANSPORT == undefined) config.WS_TRANSPORT = true
|
|
15
18
|
|
|
@@ -310,13 +313,16 @@ export function expressX(prisma, config) {
|
|
|
310
313
|
/*
|
|
311
314
|
* Create HTTP server
|
|
312
315
|
*/
|
|
313
|
-
const
|
|
316
|
+
const httpServer = createServer()
|
|
314
317
|
|
|
315
318
|
if (config.WS_TRANSPORT) {
|
|
316
319
|
/*
|
|
317
320
|
* Add websocket transport
|
|
318
321
|
*/
|
|
319
|
-
const io = new Server(
|
|
322
|
+
const io = new Server(httpServer, {
|
|
323
|
+
path: config.WS_PATH || '/socket.io/',
|
|
324
|
+
})
|
|
325
|
+
|
|
320
326
|
|
|
321
327
|
io.on('connection', async function(socket) {
|
|
322
328
|
const clientIP = socket.request?.connection?.remoteAddress || 'unknown'
|
|
@@ -456,7 +462,6 @@ export function expressX(prisma, config) {
|
|
|
456
462
|
// enhance `app` with objects and methods
|
|
457
463
|
return Object.assign(app, {
|
|
458
464
|
prisma,
|
|
459
|
-
config,
|
|
460
465
|
getSocket, setSocket,
|
|
461
466
|
createDatabaseService,
|
|
462
467
|
createService,
|
|
@@ -464,7 +469,7 @@ export function expressX(prisma, config) {
|
|
|
464
469
|
configure,
|
|
465
470
|
hooks,
|
|
466
471
|
addHttpRest,
|
|
467
|
-
|
|
472
|
+
httpServer,
|
|
468
473
|
joinChannel,
|
|
469
474
|
leaveChannel,
|
|
470
475
|
})
|