I am dealing with an error that says the web socket connection failed in my MERN web app. here is my server site code:
const http = require('http')
const { Server } = require("socket.io");
const app = express();
app.use(cors());
let server = http.createServer(app)
const io = new Server(server, {
cors: {
origin: `${process.env.MYBIYESADI}`
},
allowEIO3: true
})
io.on("connection", function (socket) {
console.log("a user connected.")
socket.on("disconnect", () => {
console.log("a user disconnected!")
io.emit("onlineUsers", users)
})
})
and frontend site code is:
import { io } from "socket.io-client";
const socket = useRef()
useEffect(() => {
socket.current = io(`${process.env.REACT_APP_API_URL}`, { transports: ["websocket"] })
}, [])
What's not written as expected? Its working fine locally and I have hosted both in wss and https as in URL but after hosting to aws docker it shows that wss connection failed as
2.647cd368.chunk.js:2 WebSocket connection to 'wss://url/socket.io/?EIO=4&transport=websocket' failed: