Делаю SPA.
Настраиваю broadcasting.
Раскомментрировал в config/app.php Broadcast классы,
в BroadcastServiceProvider добавил:
Broadcast::routes(['middleware' => ['admin', 'auth:api']]);
Конфигурация pusher на фронте:
import Pusher from 'pusher-js';
const config = {
authEndpoint: process.env.VUE_APP_PUSHER_APP_AUTH_ENDPOINT,
cluster: process.env.VUE_APP_PUSHER_APP_CLUSTER,
forceTLS: true,
auth: {
headers: {}
}
};
if (localStorage.getItem('auth.accessToken')) {
config.auth.headers = {
Authorization: `Bearer ${localStorage.getItem('auth.accessToken')}`
}
}
export const pusher = new Pusher(process.env.VUE_APP_PUSHER_APP_KEY, config);
export const updateSocketAuthToken = (accessToken) => {
pusher.config.auth.headers.Authorization =
`Bearer ${accessToken}`;
};
export const removeSocketAuthToken = () => {
pusher.config.auth.headers = {};
}
Вот так вызываю Pusher в компоненте:
async created() {
const channel = pusher.subscribe('private-platform-import');
channel.bind('platform-import-created', (data) => {
console.log(data);
});
},
beforeDestroy() {
pusher.unsubscribe('private-platform-import');
},
routes/channels.php
Broadcast::channel('user.{userId}', function ($user, $userId) {
return $user->id === $userId;
});
Broadcast::channel('platform-import', function () {
return Auth::user()->role === 'admin';
});
Но мне дает ошибку:
POST
guest-poster/api/v1/broadcasting/auth 404 (Not Found)
В чем может быть дело?