express-status-monitor
express-status-monitor copied to clipboard
How to pass socket instance
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.
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.