@@ -23,26 +23,26 @@ var RoutingProxy = exports.RoutingProxy = function (options) {
23
23
24
24
var self = this ;
25
25
options = options || { } ;
26
-
26
+
27
27
if ( options . router ) {
28
28
this . proxyTable = new ProxyTable ( options ) ;
29
29
this . proxyTable . on ( 'routes' , function ( routes ) {
30
30
self . emit ( 'routes' , routes ) ;
31
31
} ) ;
32
32
}
33
-
33
+
34
34
//
35
- // Create a set of `HttpProxy` objects to be used later on calls
35
+ // Create a set of `HttpProxy` objects to be used later on calls
36
36
// to `.proxyRequest()` and `.proxyWebSocketRequest()`.
37
37
//
38
38
this . proxies = { } ;
39
-
39
+
40
40
//
41
41
// Setup default target options (such as `https`).
42
42
//
43
43
this . target = { } ;
44
44
this . target . https = options . target && options . target . https ;
45
-
45
+
46
46
//
47
47
// Setup other default options to be used for instances of
48
48
// `HttpProxy` created by this `RoutingProxy` instance.
@@ -68,27 +68,27 @@ util.inherits(RoutingProxy, events.EventEmitter);
68
68
RoutingProxy . prototype . add = function ( options ) {
69
69
var self = this ,
70
70
key = this . _getKey ( options ) ;
71
-
71
+
72
72
//
73
73
// TODO: Consume properties in `options` related to the `ProxyTable`.
74
74
//
75
75
options . target = options . target || { } ;
76
76
options . target . host = options . target . host || options . host ;
77
77
options . target . port = options . target . port || options . port ;
78
- options . target . https = this . target && this . target . https ||
79
- options . target && options . target . https ||
78
+ options . target . https = this . target && this . target . https ||
79
+ options . target && options . target . https ||
80
80
options . https ;
81
-
81
+
82
82
//
83
83
// Setup options to pass-thru to the new `HttpProxy` instance
84
- // for the specified `options.host` and `options.port` pair.
84
+ // for the specified `options.host` and `options.port` pair.
85
85
//
86
86
[ 'https' , 'enable' , 'forward' ] . forEach ( function ( key ) {
87
87
if ( options [ key ] !== false && self [ key ] ) {
88
88
options [ key ] = self [ key ] ;
89
89
}
90
90
} ) ;
91
-
91
+
92
92
this . proxies [ key ] = new HttpProxy ( options ) ;
93
93
this . proxies [ key ] . on ( 'proxyError' , this . emit . bind ( this , 'proxyError' ) ) ;
94
94
this . proxies [ key ] . on ( 'webSocketProxyError' , this . emit . bind ( this , 'webSocketProxyError' ) ) ;
@@ -111,18 +111,18 @@ RoutingProxy.prototype.remove = function (options) {
111
111
//
112
112
RoutingProxy . prototype . close = function ( ) {
113
113
var self = this ;
114
-
114
+
115
115
if ( this . proxyTable ) {
116
116
//
117
- // Close the `RoutingTable` associated with
117
+ // Close the `RoutingTable` associated with
118
118
// this instance (if any).
119
119
//
120
120
this . proxyTable . close ( ) ;
121
121
}
122
-
122
+
123
123
//
124
124
// Close all sockets for all `HttpProxy` object(s)
125
- // associated with this instance.
125
+ // associated with this instance.
126
126
//
127
127
Object . keys ( this . proxies ) . forEach ( function ( key ) {
128
128
self . proxies [ key ] . close ( ) ;
@@ -160,11 +160,11 @@ RoutingProxy.prototype.proxyRequest = function (req, res, options) {
160
160
try {
161
161
res . writeHead ( 404 ) ;
162
162
res . end ( ) ;
163
- }
163
+ }
164
164
catch ( er ) {
165
165
console . error ( "res.writeHead/res.end error: %s" , er . message ) ;
166
166
}
167
-
167
+
168
168
return ;
169
169
}
170
170
@@ -179,15 +179,15 @@ RoutingProxy.prototype.proxyRequest = function (req, res, options) {
179
179
options . port = location . port ;
180
180
options . host = location . host ;
181
181
}
182
-
182
+
183
183
var key = this . _getKey ( options ) ,
184
184
proxy ;
185
-
185
+
186
186
if ( ! this . proxies [ key ] ) {
187
187
this . add ( options ) ;
188
-
189
- }
190
-
188
+
189
+ }
190
+
191
191
proxy = this . proxies [ key ] ;
192
192
proxy . proxyRequest ( req , res , options . buffer ) ;
193
193
} ;
@@ -206,7 +206,7 @@ RoutingProxy.prototype.proxyRequest = function (req, res, options) {
206
206
//
207
207
RoutingProxy . prototype . proxyWebSocketRequest = function ( req , socket , head , options ) {
208
208
options = options || { } ;
209
-
209
+
210
210
if ( this . proxyTable && ! options . host ) {
211
211
location = this . proxyTable . getProxyLocation ( req ) ;
212
212
@@ -217,15 +217,15 @@ RoutingProxy.prototype.proxyWebSocketRequest = function (req, socket, head, opti
217
217
options . port = location . port ;
218
218
options . host = location . host ;
219
219
}
220
-
220
+
221
221
var key = this . _getKey ( options ) ,
222
222
proxy ;
223
223
224
224
if ( ! this . proxies [ key ] ) {
225
225
this . add ( options ) ;
226
226
}
227
227
228
- proxy = this . proxies [ key ] ;
228
+ proxy = this . proxies [ key ] ;
229
229
proxy . proxyWebSocketRequest ( req , socket , head , options . buffer ) ;
230
230
} ;
231
231
@@ -237,14 +237,14 @@ RoutingProxy.prototype.proxyWebSocketRequest = function (req, socket, head, opti
237
237
// combination contained within.
238
238
//
239
239
RoutingProxy . prototype . _getKey = function ( options ) {
240
- if ( ! options || ( ( ! options . host || ! options . port )
240
+ if ( ! options || ( ( ! options . host || ! options . port )
241
241
&& ( ! options . target || ! options . target . host || ! options . target . port ) ) ) {
242
242
throw new Error ( 'options.host and options.port or options.target are required.' ) ;
243
243
return ;
244
244
}
245
245
246
246
return [
247
- options . host || options . target . host ,
247
+ options . host || options . target . host ,
248
248
options . port || options . target . port
249
249
] . join ( ':' ) ;
250
250
}
0 commit comments