WebSocket connection to 'wss://myapp.com/socket.io/?EIO=4&transport=websocket&sid=9NkQ7PBU8Mjvmp0_AAAD' failed: WebSocket is closed before the connection is established.
I can't seem to figure this out...try almost everything, would be awesome if someone can help me out here. Ig
react code = on port 3000
const ENDPOINT = "https://myapp.com/socket.io/";
const socket = io(ENDPOINT, {
withCredentials: true,
extraHeaders: {
"my-custom-header": "abcd"
}
node.js code = apps on port 8080, socket.io on port 8081
const server = http.createServer(app);
const io = socketIo(server, {
cors: {
origin: "https://www.myapp.com:3000",
methods: ["GET", "POST"],
allowedHeaders: ["my-custom-header"],
credentials: true
}});
server.listen(8081, () => console.log(`Listening on port 8081`));
nginx code = ubuntu@ip-10-0-0-000:/etc/nginx/sites-enabled/myapp.com
server_name www.myapp.com myapp.com;
location / {
root /home/ubuntu/myapp/myapp_frontend/build/;
try_files $uri /index.html;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /api/ {
proxy_pass http://127.0.0.1:8080;
}
location /socket.io/ {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/myapp.com-0001/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/davidcodedesign.com-0001/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.myapp.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = myapp.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name www.myapp.com myapp.com;
return 404; # managed by Certbot