Having gone through multiple posts on stack I still couldn't find a right answer.
Checked the documentation on CORS extension as well.
I have the following server code up and running:
var WebSocketServer = require("ws").Server
var http = require("http")
var express = require('express')
var cors = require('cors')
var app = express();
app.use(cors());
var port = process.env.PORT || 9000
var server = http.createServer(app)
server.listen(port)
var count = 0;
var clients = {};
var rooms = {};
var wss = new WebSocketServer({server: server})
wss.on("connection", function(ws) {
ws.on("create-room", function(data) {
rooms[data] = {creator : data.user_id, created : new Date()}
})
ws.on("close", function() {
console.log("websocket connection close")
})
})
But I get:
XMLHttpRequest cannot load http://localhost:9000/socket.io/?EIO=3&transport=polling&t=LE-CbU0. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:8100' is therefore not allowed access. The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute.
If I comment the line with app.use(cors());
I get :
XMLHttpRequest cannot load http://localhost:9000/socket.io/?EIO=3&transport=polling&t=LE-Cwb8. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access. The response had HTTP status code 404.
So clearly my server is up and running ok but