2

我已经安装了Laravel echo serverLaravel echo client

以下是laravel-echo-server.json配置。

{
"authHost": "http://taxation.com",
"authEndpoint": "/broadcasting/auth",
"clients": [
    {
        "appId": "APP_ID",
        "key": "someKey"
    }
],
"database": "redis",
"databaseConfig": {
    "redis": {},
    "sqlite": {
        "databasePath": "/database/laravel-echo-server.sqlite"
    }
},
"devMode": true,
"host": "127.0.0.1",
"port": "3000",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": ""
}

以下脚本侦听通道事件。它与npm run dev.

import Echo from 'laravel-echo'
let token = document.head.querySelector('meta[name="token"]');
if (token) {
    window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
    console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}
window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: '127.0.0.1:3000',
    reconnectionAttempts: 5
});


window.Echo.join('checked-in-1')
            .listen('.user.checked_in', (e) => {
            console.log(e);
        });

尝试侦听start laravel-echo-server命令中的任何事件时。它一直在扔Client can not be authenticated, got HTTP status 500

笔记 :

我真的没有在 laravel-echo-serve 和谷歌上找到任何有用的东西。

任何帮助将不胜感激。

Laravel V5.4

谢谢

4

1 回答 1

1

只是因为 CSRF 令牌而遇到问题。没有将令牌传递给回声。

window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: '127.0.0.1:3000',
    reconnectionAttempts: 5,
    csrfToken: token.content <--
});
于 2017-09-13T11:54:33.637 回答