Dave Dave - 4 months ago 14
Node.js Question

Allow websocket connection only from one URL

My websocket application accepting connections like this:

wsServer.on('request', function(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

Is here some function like
? or
When I trying connect to my websocket from different URL, my status is "pending" for a long time.
enter image description here


It's shown here:

wsServer.on('request', function(request) {
  if (! originIsAllowed(request.origin)) {
    // Make sure we only accept requests from an allowed origin 
    console.log((new Date()) + ' Connection from origin ' + request.origin + ' rejected.');

You'd have to replace originIsAllowed(request.origin) with your own check.