'Cannot connect to laravel-websocket CORS issue
I deployed my laravel application in GCP. I also set up SSL on my application https://myapp.com. It was working fine connecting to the pusher server. Then I switched to laravel-web sockets. I modified the same code in my /var/www/myapp
with the following:
.env
PUSHER_APP_ID=sample_id
PUSHER_APP_KEY=sample_key
PUSHER_APP_SECRET=samples_secret
config/broadcasting.php
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => false,
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'http'
],
'client_options' => [
// Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
],
resources/js/bootstrap.js
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
wsHost: 127.0.0.1,
wsPort: 6001,
forceTLS: false,
disableStats: true
});
Then I run it with
php artisan Webockets:serve
Then I go to my app https://myapp.com and got these errors. I am not able to connect to my WebSocket:
wss://myapp.com/app/sample_key?protocol=7&client=js&version=7.0.6&flash=false
Finished
And a series of
WebSocket connection to 'wss://myapp.com/app/sample_key?protocol=7&client=js&version=7.0.6&flash=false' failed:
Access to XMLHttpRequest at 'https://sockjs-ap1.pusher.com/pusher/app/sample_key/856/8g5crt3n/xhr_streaming?protocol=7&client=js&version=7.0.6&t=1649947314189&n=1' from origin 'https://myapp.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
POST https://sockjs-ap1.pusher.com/pusher/app/sample_key/856/8g5crt3n/xhr_streaming?protocol=7&client=js&version=7.0.6&t=1649947314189&n=1 net::ERR_FAILED
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|