D
D
dfhkjhg2020-09-13 15:18:50
Express.js
dfhkjhg, 2020-09-13 15:18:50

Express + ws pass ws to router?

There is an app.js file in which the authRoutes.js route is connected

app.use('/auth', authRoutes)

router.get('/get-data', async (req, res) => {
    try {
        const jackpot = await getData()
        //и отсюда отправить сообщение всем пользователям. Как это сделать?
        res.status(200).json(jackpot)
    } catch (e) { 
        res.status(400).json({ msg: 'invalid_request'}) 
    }
})


How to access sockets from it and send a message.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
emalsidog, 2021-06-08
@emalsidog

app.use(function (req, res, next) {
    req.wss = wss;
  next();
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question