mirror of
https://github.com/ZeroCatDev/ClassworksKV.git
synced 2025-12-07 21:13:10 +00:00
feat: 更新Socket.IO初始化配置,优化CORS设置和传输方式
This commit is contained in:
parent
e73ff53f58
commit
1e1b99a070
@ -96,14 +96,16 @@ function detectDeviceName(userAgent, headers = {}) {
|
||||
export function initSocket(server) {
|
||||
if (io) return io;
|
||||
|
||||
const allowOrigin = process.env.FRONTEND_URL || "*";
|
||||
|
||||
io = new Server(server, {
|
||||
cors: {
|
||||
origin: allowOrigin,
|
||||
origin: "*",
|
||||
methods: ["GET", "POST"],
|
||||
credentials: true,
|
||||
allowedHeaders: ["*"],
|
||||
credentials: false
|
||||
},
|
||||
// 传输方式回退策略:优先使用WebSocket,回退到轮询
|
||||
transports: ["polling", "websocket"],
|
||||
});
|
||||
|
||||
io.on("connection", (socket) => {
|
||||
@ -288,10 +290,10 @@ export function initSocket(server) {
|
||||
|
||||
// 清理socket相关缓存
|
||||
if (socket.data.currentToken) {
|
||||
// 如果这是该token的最后一个连接,考虑清理缓存
|
||||
// 如果这是该token的最后一个连接,考虑清理缓存
|
||||
const tokenSet = onlineTokens.get(socket.data.currentToken);
|
||||
if (!tokenSet || tokenSet.size === 0) {
|
||||
// 可以选择保留缓存一段时间,这里暂时保留
|
||||
// 可以选择保留缓存一段时间,这里暂时保留
|
||||
// tokenInfoCache.delete(socket.data.currentToken);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user