We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
server.on("upgrade", (request, socket, head) => { // You may check auth of request here.. // See https://github.com/websockets/ws#client-authentication const handleAuth = (ws: WebSocket) => { const { auth = () => verifyWssUrl(ws, request) } = SERVER_OPTIONS_WEAKMAP.get(server) ?? {} auth(request, ws).then((res) => { if (!res) { ws.close(1008, undefined) } else { wss.emit("connection", ws, request) } }) } wss.handleUpgrade(request, socket, head, handleAuth) })
const verifyWssUrl = async ( conn: WebSocket.WebSocket, request: http.IncomingMessage ) => { const url = request.url console.log("wss url:" + url)
try { // @ts-ignore 初始化上下文 conn.context = await context.initContext(url) // @ts-ignore console.log(conn.context) } catch (error: any) { console.error("初始化上下文失败", error) return false }
return true }
The text was updated successfully, but these errors were encountered:
big-camel
No branches or pull requests
server.on("upgrade", (request, socket, head) => {
// You may check auth of request here..
// See https://github.com/websockets/ws#client-authentication
const handleAuth = (ws: WebSocket) => {
const { auth = () => verifyWssUrl(ws, request) } =
SERVER_OPTIONS_WEAKMAP.get(server) ?? {}
auth(request, ws).then((res) => {
if (!res) {
ws.close(1008, undefined)
} else {
wss.emit("connection", ws, request)
}
})
}
wss.handleUpgrade(request, socket, head, handleAuth)
})
const verifyWssUrl = async (
conn: WebSocket.WebSocket,
request: http.IncomingMessage
) => {
const url = request.url
console.log("wss url:" + url)
try {
// @ts-ignore 初始化上下文
conn.context = await context.initContext(url)
// @ts-ignore
console.log(conn.context)
} catch (error: any) {
console.error("初始化上下文失败", error)
return false
}
return true
}
The text was updated successfully, but these errors were encountered: