gpt4 book ai didi

php - 响应中 'Access-Control-Allow-Origin' header 的值不得为laravel-echo-server中的通配符 '*'错误

转载 作者:行者123 更新时间:2023-12-03 12:03:51 28 4
gpt4 key购买 nike

为了使laravel应用成为实时应用,我想使用socket-io。

客户端是由ionic框架编写的移动应用程序,运行在192.168.1.7:8100上。

要配置和运行socket-io Server,我安装了[laravel-echo-server][1]

这是要运行套接字io服务器的larvel echo服务器配置文件:

{
"authHost": "http://api.pars-app.dev",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "1924bf1d59b3759d",
"key": "keykeykey"
}
],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": "3000",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": ""
}

首先,我使用以下命令运行redis服务器:
redis-server --port 3001

然后使用此命令运行soketio服务器:
laravel-echo-server start

结果是这样的:
L A R A V E L  E C H O  S E R V E R

version 1.2.7

⚠ Starting server in DEV mode...

✔ Running at localhost on port 3000
✔ Channels are ready.
✔ Listening for http events...
✔ Listening for redis events...

Server ready!

这是Echo laravel js:
window.echo = new Echo({
broadcaster: 'socket.io',
host: 'http://192.168.1.7:3000',
auth: {
headers: {
Authorization: 'bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjUsImlzcyI6Imh0dHA6XC9cL2FwaS5wYXJzLWFwcC5kZXZcL3YxXC9hdXRoXC9zaWduSW4iLCJpYXQiOjE0OTI2NzU3OTgsImV4cCI6MTQ5NTI2Nzc5OCwibmJmIjoxNDkyNjc1Nzk4LCJqdGkiOiI5OTE3YTA4OWY0MDI4NjMwOTU5NWZmYjZmODQ2MTk5ZSJ9.oOFRmxQoiLS8BJksPkf6CQSVOcDR7rPApS71S6nZO5c'
}
}
});

但是,当我在 中运行主应用程序时,Chrome 浏览器在控制台中出现以下错误:
XMLHttpRequest cannot load http://192.168.1.7:3000/socket.io/?EIO=3&transport=polling&t=LkQ5Rnb. The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://192.168.1.7:8100' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

我尝试了许多解决方案来解决此问题,例如 This Answer,但问题仍然存在。

最佳答案

您是否尝试使用虚拟主机替换IP地址?

并像这样配置

ServerName your-domain.dev

DocumentRoot /var/www/html/your_project/public

<Directory "/var/www/html/your_project/public">
AllowOverride all
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT, PATCH"
Header set Access-Control-Max-Age "1000"
Header set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept"
</Directory>

并运行SocketIO监听并调用您的域。

希望对您有所帮助。我已经在我的项目中使用了SocketIO。

我正在使用PM2来运行SocketIO。

关于php - 响应中 'Access-Control-Allow-Origin' header 的值不得为laravel-echo-server中的通配符 '*'错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43569342/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com