@@ -51,16 +51,8 @@ var connectUtils = {
5151
5252 var socket = options . get ( "socket" ) ;
5353 var template = fs . readFileSync ( config . templates . connector , "utf-8" ) ;
54- var connectionUrl = require ( "url" ) . parse ( socket . get ( "namespace" ) ) ;
5554 var url = connectUtils . getConnectionUrl ( options ) ;
5655
57- /**
58- * If namespace is a URL, just return it
59- */
60- if ( connectionUrl . host && connectionUrl . protocol ) {
61- url = "'%s'" . replace ( "%s" , socket . get ( "namespace" ) ) ;
62- }
63-
6456 template = template
6557 . replace ( "%path%" , socket . get ( "path" ) )
6658 . replace ( "%url%" , url ) ;
@@ -69,6 +61,12 @@ var connectUtils = {
6961 } ,
7062 getConnectionUrl : function ( options ) {
7163
64+ var socketOpts = options . get ( 'socket' ) . toJS ( ) ;
65+
66+ if ( ! socketOpts . namespace . match ( / ^ \/ / ) ) {
67+ socketOpts . namespace = "/" + socketOpts . namespace ;
68+ }
69+
7270 var protocol = "" ;
7371 var withHostnamePort = "'{protocol}' + location.hostname + ':{port}{ns}'" ; //
7472 var withHost = "'{protocol}' + location.host + '{ns}'" ; //
@@ -82,17 +80,18 @@ var connectUtils = {
8280 string = withHostnamePort ;
8381 }
8482
85- var socketOpts = options . get ( 'socket' ) ;
86-
87- if ( socketOpts . has ( 'domain' ) ) {
83+ if ( socketOpts . domain ) {
8884 string = withDomain ;
85+ if ( typeof socketOpts . domain === "function" ) {
86+ socketOpts . domain = socketOpts . domain . call ( null , options ) ;
87+ }
8988 }
9089
9190 return string
9291 . replace ( "{protocol}" , protocol )
9392 . replace ( "{port}" , options . get ( "port" ) )
94- . replace ( "{domain}" , socketOpts . get ( " domain" ) )
95- . replace ( "{ns}" , socketOpts . get ( " namespace" ) ) ;
93+ . replace ( "{domain}" , socketOpts . domain )
94+ . replace ( "{ns}" , socketOpts . namespace ) ;
9695 } ,
9796 /**
9897 * @param {Object } [options]
0 commit comments