Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thinkjs 2.2 websocket无法连接成功 #1711

Open
tanliang2 opened this issue Nov 5, 2022 · 0 comments
Open

thinkjs 2.2 websocket无法连接成功 #1711

tanliang2 opened this issue Nov 5, 2022 · 0 comments

Comments

@tanliang2
Copy link

DESC

ENV

OS Platform:win10

Node.js Version:18.12.0

ThinkJS Version:2.2.9
错误信息:
test.html:1 Access to XMLHttpRequest at 'http://127.0.0.1:8360/socket.io/?EIO=3&transport=polling&t=OH8mmgq' from origin 'http://localhost:63342' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

sever端配置:
export default {
on: true, //是否开启 WebSocket
type: 'socket.io', //使用的 WebSocket 库类型,默认为 socket.io
allow_origin: 'http://127.0.0.1', //允许的 origin
adp: undefined, // socket 存储的 adapter,socket.io 下使用
path: '', //url path for websocket
messages: {
open: 'home/socketio/open',
},
};
客户端:代码:
import io from "socket.io-client"
const socket = io('http://127.0.0.1:8360');

function sendOpen(){
//发送事件
socket.emit('open', 'data');
//监听事件
socket.on('open', function(data){
console.log("open call back")
})
console.log("open")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant