Php 授权SPA中的广播频道
我的项目分为两个应用程序:基于vue的客户端应用程序和基于laravel的服务器端RESTAPI应用程序。我在Php 授权SPA中的广播频道,php,laravel,single-page-application,laravel-echo,Php,Laravel,Single Page Application,Laravel Echo,我的项目分为两个应用程序:基于vue的客户端应用程序和基于laravel的服务器端RESTAPI应用程序。我在config/App.php文件中取消了App\Providers\BroadcastServiceProvider::class的注释 默认的广播授权路由是,/broadcasting/auth。由于它应用了web中间件,因此由于CSRF问题,它显示了419。因此,在BroadcastServiceProvider中,我更改了以下内容: Broadcast::routes(); 为此
config/App.php
文件中取消了App\Providers\BroadcastServiceProvider::class的注释
默认的广播授权路由是,/broadcasting/auth
。由于它应用了web
中间件,因此由于CSRF问题,它显示了419。因此,在BroadcastServiceProvider
中,我更改了以下内容:
Broadcast::routes();
为此:
Broadcast::routes(['middleware' => ['auth:api']]);
但现在的问题是,每当我访问客户端应用程序时,控制台中都会出现以下错误:
获取405(不允许使用方法)
我该如何解决这个问题
我的客户端配置:
window.Echo = new Echo({
authEndpoint: 'http://localhost:8000/broadcasting/auth',
broadcaster: 'pusher',
key: 'anyKey',
wsHost: window.location.hostname,
wsPort: 6001,
disableStats: true
});
window.Echo.private('test.1').listen('TestUpdated', (e) => {
/*eslint-disable no-console*/
console.log(e);
});
这就是我在api.php
routes文件中所做的:
Route::post('/broadcast',function (Request $request){
$pusher = new Pusher\Pusher(env('PUSHER_APP_KEY'),env('PUSHER_APP_SECRET'), env('PUSHER_APP_ID'));
return $pusher->socket_auth($request->request->get('channel_name'),$request->request->get('socket_id'));
});
然后,我在客户端应用程序中将authEndpoint
更改为该路由:
window.Echo = new Echo({
authEndpoint: 'http://localhost:8000/broadcast',
...
}