Q
Q
qu1kgg2020-07-14 14:12:51
CORS
qu1kgg, 2020-07-14 14:12:51

Why is the socket not working through cloudflare?

Tell me, if the domain is linked to cloudflare, cloudflare issued its ssl, how can I run my application on https?
I tried to set ssl keys, those that were issued by reg ru, but this way the application thinks that the domain is third-party and gives an error:

Access to XMLHttpRequest at 'https://ДОМЕН:8443/socket.io/?EIO=3&transport=polling&t=NDD1BTS' from origin 'https://ДОМЕН' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

My app.js:
var https = require('https');
var fs = require('fs');
var options = {
  key: fs.readFileSync('/var/www/html/server/key.txt'),
  cert: fs.readFileSync('/var/www/html/server/certificate.crt')
};
const app = require('express')(),
    server = https.createServer(options, app),
    Redis = require('redis'),
    RedisClient = Redis.createClient(),
    io = require('socket.io')(server),
    axios = require('axios');

const myArgs = process.argv.slice(2);
const domain = myArgs[0];
const SECRET_KEY = '';

axios.defaults.baseURL = domain + '/api/bot/';
server.listen(8433);

How to run a socket on https using a cloud domain?

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