V
V
VegasChickiChicki2020-10-19 15:22:08
Nginx
VegasChickiChicki, 2020-10-19 15:22:08

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,
    }]
  },


On the server side:
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'));


I can't figure out what's wrong. The problem is that everything works for me specifically. I open a tab with the application, write something in the chat and everything arrives and is displayed in the second one, but other people do not. It throws an error with the text:
GET localhost:8080/socket.io ...
net::ERR_CONNECTION_REFUSED

5f8d843ebba4d205611983.png

I assume that I issued rights on the server for my ip while working, maybe this is the problem?
Where to dig, maybe this is due to the fact that there is no ssl o_O? Maybe somehow you need to configure nginx or ubuntu? I just started looking into this and haven't been able to find an answer yet...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
VegasChickiChicki, 2020-10-19
@VegasChickiChicki

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,
    }]
  }

Андрей Гаврилов, 2020-10-19
@thexaver

Проксируйте 8080 порт и нет проблем

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question