@@ -51,16 +51,8 @@ var connectUtils = {
51
51
52
52
var socket = options . get ( "socket" ) ;
53
53
var template = fs . readFileSync ( config . templates . connector , "utf-8" ) ;
54
- var connectionUrl = require ( "url" ) . parse ( socket . get ( "namespace" ) ) ;
55
54
var url = connectUtils . getConnectionUrl ( options ) ;
56
55
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
-
64
56
template = template
65
57
. replace ( "%path%" , socket . get ( "path" ) )
66
58
. replace ( "%url%" , url ) ;
@@ -69,6 +61,12 @@ var connectUtils = {
69
61
} ,
70
62
getConnectionUrl : function ( options ) {
71
63
64
+ var socketOpts = options . get ( 'socket' ) . toJS ( ) ;
65
+
66
+ if ( ! socketOpts . namespace . match ( / ^ \/ / ) ) {
67
+ socketOpts . namespace = "/" + socketOpts . namespace ;
68
+ }
69
+
72
70
var protocol = "" ;
73
71
var withHostnamePort = "'{protocol}' + location.hostname + ':{port}{ns}'" ; //
74
72
var withHost = "'{protocol}' + location.host + '{ns}'" ; //
@@ -82,17 +80,18 @@ var connectUtils = {
82
80
string = withHostnamePort ;
83
81
}
84
82
85
- var socketOpts = options . get ( 'socket' ) ;
86
-
87
- if ( socketOpts . has ( 'domain' ) ) {
83
+ if ( socketOpts . domain ) {
88
84
string = withDomain ;
85
+ if ( typeof socketOpts . domain === "function" ) {
86
+ socketOpts . domain = socketOpts . domain . call ( null , options ) ;
87
+ }
89
88
}
90
89
91
90
return string
92
91
. replace ( "{protocol}" , protocol )
93
92
. 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 ) ;
96
95
} ,
97
96
/**
98
97
* @param {Object } [options]
0 commit comments