O
O
olezhenka2019-04-17 13:50:28
JavaScript
olezhenka, 2019-04-17 13:50:28

Can't connect to sockets?

Server part

// Express
const express = require('express');
const helmet = require('helmet');
const bodyParser = require('body-parser');
const PORTs = 8433;

// app
const app = express();
app.disable('x-powered-by');
app.set('trust proxy', 1);
app.use(helmet());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(function(req, res, next) {
  req.result = {errors: []};
  next();
})

// Routes
app.use('/api', require('./routes/index'));

// Error handling
app.use(require('./controllers/error_handling'));
app.use(require('./controllers/error_404'));



// Create Server
const httpsServer = require('https').createServer(credentials, app); // https



// Socket io
const io = require('socket.io')(httpsServer, {
  path: '/socket'
});
io.on('connection', socket => {
  console.log('user socket connected: ', socket);
})


// Listen
httpsServer.listen(PORTs, () => console.log(`App started on port ${PORTs}`)); // https


Client side
import VueSocketIO from 'vue-socket.io'
Vue.use(new VueSocketIO({
    debug: true,
    connection: 'https://aaa.ru:8433',
    vuex: {
        store,
        actionPrefix: 'SOCKET_',
        mutationPrefix: 'SOCKET_'
    },
    options: { path: '/socket' }
}))


Connection does not happen and I can not even understand the problem in the server or client part
. Maybe I do not see an obvious error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
olezhenka, 2019-04-17
@olezhenka

In general, the problem was that nginx was proxying requests from port 433 to port 8433 and it was necessary to connect sockets on port 433, not 8433

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question