mardi 24 avril 2018

Configure laravel-echo-server on a different domain (error 400 handshake)

I need help, I just setup a laravel-echo-server for my application.

My app is on https://my-domain.com.

My laravel echo was on https://my-domain.com:6001, but I moved it to https://redis.my-domain.com

When I try to go to https://redis.my-domain.com/socket.io/socket.io.js, I get the right file. (That's works !)

But my application send me an error while trying to use WebSocket..


"websocket connection to 'wss://redis.my-domain.com/socket.io?EIO=3&transport=websocket&sid=qsqs[......]' failed: Error during WebSocket handshake: Unexpected response code: 400"


How can I fix it ? Let see the laravel-echo-server.json :

{
        "authHost": "https://my-domain.com",
        "authEndpoint": "/broadcasting/auth",
        "clients": [
                {
                        "appId": "***********",
                        "key": "****************************"
                }
        ],
        "database": "redis",
        "databaseConfig": {
                "redis": {},
                "sqlite": {
                        "databasePath": "/database/laravel-echo-server.sqlite"
                }
        },
        "devMode": false,
        "host": null,
        "port": "6001",
        "protocol": "https",
        "socketio": {
                "transports": "websocket",
                "allowUpgrades": true
        },
        "sslCertPath": "/etc/letsencrypt/live/redis.my-domain.com/cert.pem",
        "sslKeyPath": "/etc/letsencrypt/live/redis.my-domain.com/privkey.pem",
        "sslCertChainPath": "",
        "sslPassphrase": "",
        "apiOriginAllow": {
                "allowCors": true,
                "allowOrigin": "https://my-domain.com",
                "allowMethods": "GET, POST",
                "allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id"
        }
}

And my JS file

import Echo from 'laravel-echo';

let e = new Echo({
        broadcaster : 'socket.io',
        host: 'redis.my-domain.com',
});

var listen_channel = function(channel){
        e.channel(channel)
        .listen("BroadcastMessageEvent", function(e){
                var broadcast = '<div class="bradcast_box container-fluid"><div class="broadcast_message">'+ e.message +'</div></div>'
                $('body').append(broadcast);
        });
}

$(document).ready(function(){
        listen_channel('general'); 
});

window.listen_channel = listen_channel; 

Thank you for help !

I tried every thing I can do.

Have a nice day


Config : Apache 2.4

Laravel : 5.6

PHP : 7.2

NPM : 5.8.0

Node : 8.11.1



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire