我的websocket应用程序接受这样的连接:
wsServer.on('request', function(request) {
console.log(request);
if(request.origin == "https://www.my-domain.com"){
var connection = request.accept(null, request.origin);
/* some lines of code
...
*/
} else {
//here I want block request
}
这里有一些像.decline()
这样的功能吗?还是.notAccept()
或......?
当我尝试从不同的URL连接到我的websocket时,我的状态为" pending"需很长时间。
答案 0 :(得分:1)
显示here:
wsServer.on('request', function(request) {
if (! originIsAllowed(request.origin)) {
// Make sure we only accept requests from an allowed origin
request.reject();
console.log((new Date()) + ' Connection from origin ' + request.origin + ' rejected.');
return;
}
...
});
您必须用自己的支票替换originIsAllowed(request.origin)
。