Dave Dave - 1 year ago 109
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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download