AbdoPrDZ / fixed-laravel-echo-server

The fixed version of laravel-echo-server (upgrade socket.io version to latest)
MIT License
1 stars 1 forks source link

Client side link keeps prompting 400 (Bad Request) #3

Open cnjackven opened 5 months ago

cnjackven commented 5 months ago

After deploying fixed-laravel-echo-server, the client side link keeps prompting 400 (Bad Request), can you help me?

"laravel-echo": "^1.16.1", "socket.io-client": "^4.7.5",

import Echo from 'laravel-echo'
import io from 'socket.io-client'

window.io = io
window.Echo = new Echo({
  broadcaster: 'socket.io',
  host: 'test.com', 
  auth: {
    headers: {
      Authorization:
        'Bearer request token' 
    }
  }
})
window.Echo.private('im.chat.message.12345').listen('.chat.message', (e) => {
  console.log( e)
})

NGINX server

        #the following would go within the server{} block of your web server config
    location /socket.io {
        proxy_pass http://127.0.0.1:6001; #could be localhost if Echo and NginX are on the same box
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }

ERROR:

Access to XMLHttpRequest at 'http://test.com/socket.io/?EIO=3&transport=polling&t=OyJ3I6q' from origin 'http://localhost:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

[root@test test.com]# curl http://127.0.0.1:6001?EIO=3&transport=polling&t=OyJIoDI
[1] 154304
[2] 154305
[root@test test.com]# {"success":true,"message":"OK","headers":["*/*"]}

clientConnectEndpoint and clientDisconnectEndpoint must be set?

AbdoPrDZ commented 5 months ago

HI there

could you provide me your fixed-laravel-echo-server.json config file?.

no clientConnectEndpoint and clientDisconnectEndpoint is not required

cnjackven commented 5 months ago

fixed-laravel-echo-server.json

{
    "authHost": "http://test.com",
    "authEndpoint": "/broadcasting/auth",
    "clientConnectEndpoint": null,
    "clientDisconnectEndpoint": null,
    "clients": [
        {
            "appId": "8a92a751ea66edf8",
            "key": "df5411b2e3ecc51673ddf374e6c07c31"
        }
    ],
    "database": "sqlite",
    "databaseConfig": {
        "redis": {
            "port": 6379,
            "host": "127.0.0.1",
            "db": "0",
            "password": ""
        },
        "sqlite": {
            "databasePath": "/database/fixed-laravel-echo-server.sqlite"
        }
    },
    "devMode": true,
    "host": null,
    "port": "6001",
    "protocol": "http",
    "socketIO": {},
    "secureOptions": 67108864,
    "sslCertPath": "",
    "sslKeyPath": "",
    "sslCertChainPath": "",
    "sslPassphrase": "",
    "subscribers": {
        "http": true,
        "redis": true
    },
    "apiOriginAllow": {
        "allowCors": false,
        "allowOrigin": "http://test.com",
        "allowMethods": "GET, POST",
        "allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id"
    },
    "firebaseAdmin": {
        "enabled": false,
        "configSource": null,
        "databaseURL": null,
        "channel": "private-firebase_admin"
    },
    "echoSever": null
}
AbdoPrDZ commented 5 months ago

I did not find the main problem, but we will try some solutions 1- Try setting transports to websockets in echo client config

window.Echo = new Echo({
  broadcaster: 'socket.io',
  host: 'test.com', 
  transports: ["websocket"],
  auth: {
    headers: {
      Authorization:
        'Bearer request token' 
    }
  }
})

(sorry for my late response)