0

Server-side code:

const express = require("express");
const app = express();
const http = require("http");
const { Server } = require("socket.io");
const cors = require("cors");

app.use(cors());

const server = http.createServer(app);

const io = new Server(server, {
  cors: {
    origin: "http://localhost:3000",
    methods: ["GET", "POST"],
  },
});

io.on("connection", (socket) => {
  console.log(`User Connected: ${socket.id}`);

  socket.on("join_room", (data) => {
    socket.join(data);
  });

Client-side code:

import io from "socket.io-client";

const socket = io.connect("http://localhost:8080");

function App() {

  const joinRoom = () => {
    if (room !== "") {
      socket.emit("join_room", room);
    }
  };

But getting the following error after hosting it to cloudflare which works fine in local.:

polling.js:311 GET http://localhost:8080/socket.io/?EIO=4&transport=polling&t=OKgPK3u net::ERR_CONNECTION_REFUSED

I tried giving different port but still facing the same problem. Can anyone please help me?

0 Answers0