I have a Socket.IO server that is running on a Kubernetes cluster with a public DNS name for the server. I also have a Vue.js front-end application running from an AWS S3 bucket.
I am running into an issue where when I send a curl request to the server as the docs suggest to do to debug CORS issues I am getting back a 400 which is due to a CORS issue on the Socket.IO side of this according to this SO post
So far I have tried using the DNS same of the DNS name I have set to for the S3 bucket which is the origin of the request. I have also tried * and *:* with no luck. I am including my server.js code and main.js (vue) in hopes someone might know what is wrong and why my application is not working.
server.js
// package imports above here
const server = http.createServer();
const io = require("socket.io")(server, {
cors: {
origin: "*:*",
methods: ["GET", "POST"],
transports: ['websocket', 'polling'],
},
allowEIO3: true,
adapter: require("socket.io-redis")({
pubClient: redisClient,
subClient: redisClient.duplicate(),
}),
});
io.on("connect_error", (err) => {
console.log(`connect_error due to ${err.message}`);
});
io.on('connection', function(socket){
// business logic redacted
});
const PORT = process.env.PORT || 9000;
server.listen(PORT, () => {
console.log(`Server running on port ${PORT}`)
});
main.js - vue.js
import io from 'socket.io-client'
import VueSocketIO from 'vue-socket.io'
const socket = io.connect(process.env.VUE_APP_SOCKET_URL) // socket.mydomain.com -- this is the socket.io server's public DNS address
Vue.use(new VueSocketIO({
debug: true,
connection: socket,
vuex: {
store,
actionPrefix: "SOCKET_",
mutationPrefix: "SOCKET_"
}
})
);
Error message as seen in nginx-ingress
[18/Jun/2021:20:43:09 +0000] "GET /socket.io/?EIO=4&transport=polling HTTP/2.0" 400 11 "-" "curl/7.68.0" │
│ 87 0.003 [backend-socketio-9000] [] 100.96.2.30:9000 11 0.004 400 a7a1f4b4a6c545999771c93a5aeb7f98