bootstrap.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * We'll load the axios HTTP library which allows us to easily issue requests
  3. * to our Laravel back-end. This library automatically handles sending the
  4. * CSRF token as a header based on the value of the "XSRF" token cookie.
  5. */
  6. import Echo from "laravel-echo";
  7. import axios from "axios";
  8. /**
  9. * Echo exposes an expressive API for subscribing to channels and listening
  10. * for events that are broadcast by Laravel. Echo and event broadcasting
  11. * allows your team to easily build robust real-time web applications.
  12. */
  13. import Pusher from "pusher-js";
  14. window.axios = axios;
  15. window.axios.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";
  16. window.Pusher = Pusher;
  17. let forceTLS = window.location.protocol === "https:";
  18. let options = {
  19. broadcaster: "reverb",
  20. key: import.meta.env.VITE_REVERB_APP_KEY,
  21. wsHost: import.meta.env.VITE_REVERB_HOST ?? window.location.hostname,
  22. forceTLS: forceTLS,
  23. enabledTransports: forceTLS ? ["wss"] : ["ws"],
  24. };
  25. let port = import.meta.env.VITE_REVERB_PORT;
  26. if (forceTLS) {
  27. options.wssPort = port ?? 443;
  28. } else {
  29. options.wsPort = port ?? 80;
  30. }
  31. window.Echo = new Echo(options);