express-status-monitor icon indicating copy to clipboard operation
express-status-monitor copied to clipboard

How to pass socket instance

Open dfa1234 opened this issue 6 years ago • 1 comments

According to the doc we need to configure the monitor before any endpoint

    const app: Application = express();
    app.use(require('express-status-monitor')({
        path: '/status',
    }));

But I dont create the socket until the end. Simplified version is like this:

    const server = require('http').createServer(app);

    server.listen('3113', () => {
        console.log('server started');
    });

    const io = require('socket.io')(server);

    io.on('connection', socket => {
        socket.on('event-socket', data => {
            // socket stuff
        });
    }

I presume I need to insert the existingSocketIoInstance at the beginning but I dont figure how it is possible? My const io need server which need a full configured app express server.

dfa1234 avatar Aug 30 '19 09:08 dfa1234

Try the following using express-status-monitor@^1.3.4?

    const server = require('http').createServer(app);

    server.listen('3113', () => {
        console.log('server started');
    });

    const io = require('socket.io')(server);

    app.use(require('express-status-monitor')({
        websocket: io,
    }));

Alternatively, you don't need to create a separate socket.io as it will be automatically created for you.

lamweili avatar May 09 '22 18:05 lamweili