Answer the question
In order to leave comments, you need to log in
How to properly configure socket.io and vps server to work correctly?
The bottom line is that I'm trying to figure out how sockets work.
There is a nuxt application, the sockets in it are connected like this:
//nuxt.config.js
modules: [
'nuxt-socket-io',
],
io: {
sockets: [{
name: 'main',
url: 'http://localhost:8080',
default: true,
}]
},
const app = require('express')();
const http = require('http').createServer(app);
const cors = require('cors');
const io = require('socket.io')(http);
app.use(cors());
io.on('connection', socket => {
console.log('a user connected');
socket.on('NewMessage', msg => {
io.emit('update-chat', msg);
});
});
app.get('/', (req, res) => res.send('api-server is ready to work!'));
http.listen(8080, () => console.log('Example app listening on port 8080'));
Answer the question
In order to leave comments, you need to log in
Solved a problem. The bottom line is that during my work I had a local server turned on, I don’t know if this is the case or not, but I have a suspicion that requests from the site went exactly there, for other users, accordingly, nothing worked, since they didn’t have anything running locally :)
I changed the nuxt config setting as follows:
io: {
// module options
sockets: [{
name: 'main',
url: process.env.NODE_ENV !== 'production'? 'http://localhost:8080' : 'http://194.194.194.194:8080',
default: true,
}]
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question