首页 > 解决方案 > Laravel CORS在 https://sockjs.pusher.com/pusher/app/AB/13/heelec9r/xhr_streaming?protocol=7&client=js&version=7.0.3&t=162&n=6 访问 XMLHttpRequest

问题描述

请帮忙..我正在使用laravel websocket(https://beyondco.de/docs/laravel-websockets/getting-started/introduction)进行实时聊天..它在我的本地机器上工作..但是当我部署到服务器..这是错误说:https ://ibb.co/QKxFDmJ

Access to XMLHttpRequest at 'https://sockjs.pusher.com/pusher/app/ABCDEFG/232/15de5kkf/xhr?protocol=7&client=js&version=7.0.3&t=1622612993897&n=52' from origin 'http://ipaddress' 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.
app.js:24458 POST https://sockjs.pusher.com/pusher/app/ABCDEFG/232/15de5kkf/xhr?protocol=7&client=js&version=7.0.3&t=1622612993897&n=52 net::ERR_FAILED[![enter image description here][1]][1]

广播.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'),
                'host' => '127.0.0.1',
                'port' => 6001,
                'scheme' => 'http',
            ],
        ],

引导程序.js

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    wsHost: window.location.hostname,
    wsPort: 6001,
    wssPort: 6001,
    disableStats: true,
    forceTLS: true
});

标签: laravellaravel-websockets

解决方案


推荐阅读