A
A
artyak11212019-07-25 13:13:30
Apache HTTP Server
artyak1121, 2019-07-25 13:13:30

How to solve the problem with Socket.io and Https?

I put the script of the roulette of things. There is a bunch of apache + nodejs + socket.io. If you go to the site by IP address, then the site connects to the bot via a socket, everything is fine in the console. If you go to the site by domain, then it swears with two errors:

GET https://site.ru:2053/socket.io/?EIO=3&transport=polling&t=1564049380135-11 521

Access to XMLHttpRequest at 'https://site.ru:2053/socket.io/?EIO=3&transport=polling&t=1564049380135-11' from origin 'https://site.ru' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.


I tried to configure CORS by adding to .htaccess
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>

but didn't help.

On the site in the scripts, the connection is also used, I
var socket = io.connect(':2053');also tried to specify var socket = io.connect(https://site.ru':2053');it, nothing helped.

App.js to start the bot is used with the following config:

var auth = require('http-auth'),
    scribe = require('scribe-js')(),
    console = process.console,
    config = require('./config.js'),
    app = require('express')(),
    server = require('https').Server(app),
    io = require('socket.io')(https),
    redis = require('redis'),
    requestify = require('requestify'),
  
  fs = require('fs'),
    privateKey = fs.readFileSync('/var/www/bot/keys/privkey.pem'),
    certificate = fs.readFileSync('/var/www/bot/keys/cert.pem'),
    credentials = {key: privateKey, cert: certificate},
    https = require('https').Server(credentials,app);

https.listen(config.serverPort);


I'm using cloudflare, so port 2053 is the one they have open.

What could be the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question