laravel / echo

Laravel Echo library for beautiful Pusher and Ably integration.
https://laravel.com/docs/broadcasting#client-side-installation
MIT License
1.19k stars 185 forks source link

how to change pusher host to connect to /broadcasting/auth on a different domain? #189

Closed vesper8 closed 6 years ago

vesper8 commented 6 years ago

My vue site is https://www.xxx.com and my Laravel api is https://api.xxx.com

I use Laravel Echo with Pusher and it always wants to use https://www.xxx.com/broadcasting/auth to join my channels.

I need it to be https://api.xxx.com/broadcasting/auth

I have jwt.auth and cors working correctly already, but no matter what I do, setting the host, wsHost or httpHost, it doesn't respect my setting. It ignores it completely if I change the 'host' and if I set the wsHost/httpHost it then tries to connect to a /pusher/app url with lots of url parameters and doesn't try to connect to /broadcasting/auth anymore

It was working fine when both the laravel backend and vue front-end was on the same domain.. but now that I decoupled them I can't get it to change the host

I'm really stuck here.. some help would be so appreciated!

vesper8 commented 6 years ago

I think this must be a bug because after I did

console.log(window.Echo.connector.pusher.config.host);

It does show my custom host.. yet it ignores that host and uses the current domain instead

Finally I found a way to force it to use the domain I want by doing this:

window.Echo.connector.pusher.config.authEndpoint = `https://api.xxx.com/broadcasting/auth`;
morloderex commented 6 years ago

When you instantiate echo you can pass in authEndpoint to it.

It looks like every configuration is passed down towards the underlaying Pusher configuration instance.

PusherConnector Constructor.

https://github.com/laravel/echo/blob/bf936736f7def1b89554ac9227b1bfe21f91b526/src/connector/pusher-connector.ts#L33

Echo constructor.

https://github.com/laravel/echo/blob/bf936736f7def1b89554ac9227b1bfe21f91b526/src/echo.ts#L45

Here is a list of possible Pusher specific configuration keys: https://github.com/pusher/pusher-js#configuration

So just do it that way. :)

driesvints commented 6 years ago

Can you try @morloderex's solution to see if that works?

lukasz-madon commented 2 years ago

just add it to the config


    window.Echo = new Echo({
      broadcaster: 'pusher',
      authEndpoint: `https://xxxx/broadcasting/auth`,
      cluster: 'us3',
      forceTLS: true,
      auth: {
        headers: {
          Authorization: 'Bearer ' + jwt
        },
      },
    });
parallels999 commented 2 years ago

@lukasz-madon on next version you can use bearerToken option

window.Echo = new Echo({
  broadcaster: 'pusher',
  authEndpoint: `https://xxxx/broadcasting/auth`,
  cluster: 'us3',
  forceTLS: true,
  bearerToken: jwt,
  /*auth: {
    headers: {
      Authorization: 'Bearer ' + jwt
    },
  },*/
});
Enzo-PVsyst commented 1 year ago

I'm still having this issue, even by using direclty authEndPoint, it doesn't affect my configuration at all, anything on this has been updated ? I can't make it work on different domains.