mirror of
https://github.com/chaos-zhu/easynode.git
synced 2026-10-07 17:27:53 +08:00
24 lines
479 B
JavaScript
24 lines
479 B
JavaScript
import { Server } from 'socket.io'
|
|
import { verifyWsAuthSync } from './verify-auth.js'
|
|
import { registerSocketServer } from './auth-session.js'
|
|
|
|
const createSecureWs = (httpServer, path, otherConfig = {}) => {
|
|
const serverIo = new Server(httpServer, {
|
|
path,
|
|
cors: {
|
|
origin: true,
|
|
credentials: true
|
|
},
|
|
...otherConfig
|
|
})
|
|
// 鉴权
|
|
serverIo.use(verifyWsAuthSync)
|
|
registerSocketServer(serverIo)
|
|
|
|
return serverIo
|
|
}
|
|
|
|
export {
|
|
createSecureWs
|
|
}
|