2
2
* Command Line Manager to parse the command line arguments
3
3
* and set the necessary fields in RdGlobalConfig.
4
4
*/
5
-
6
5
var constants = require ( '../config/constants' ) ;
6
+
7
7
var RdGlobalConfig = constants . RdGlobalConfig ;
8
8
9
9
var CommandLineManager = {
@@ -13,21 +13,25 @@ var CommandLineManager = {
13
13
+ "\n"
14
14
+ "Usage: RequestsDebugger [ARGUMENTS]\n\n"
15
15
+ "ARGUMENTS:\n"
16
- + " --port <port> : Port on which the Requests Debugger Tool's Proxy will run\n"
17
- + " Default: " + RdGlobalConfig . RD_HANDLER_PORT + "\n"
18
- + " --proxy-host <hostname> : Hostname of the Upstream Proxy\n"
19
- + " --proxy-port <port> : Port of the Upstream Proxy. Default: " + constants . DEFAULT_PROXY_PORT + " (if hostname is provided)\n"
20
- + " --proxy-user <username> : Username for auth of the Upstream Proxy\n"
21
- + " --proxy-pass <password> : Password for auth of the Upstream Proxy\n"
22
- + " --retry-delay <milliseconds> : Delay for the retry of a failed request. Default: " + RdGlobalConfig . RETRY_DELAY + "ms\n"
23
- + " --request-timeout <milliseconds> : Hard timeout for the requests being fired by the tool before receiving any response\n"
24
- + " Default: " + RdGlobalConfig . CLIENT_REQ_TIMEOUT + "ms\n"
25
- + " --logs-path <relative/absolute path> : Directory where the '" + constants . LOGS_FOLDER + "' folder will be created\n"
26
- + " for storing logs. Default: Current Working Directory\n"
27
- + " --del-logs : Deletes any existing logs from the " + constants . LOGS_FOLDER + "/ directory and initializes\n"
28
- + " new files for logging\n"
29
- + " --help : Help for Requests Debugger Tool\n"
30
- + " --version : Version of the Requests Debugger Tool\n" ;
16
+ + " --proxy-port <port> : Port on which the Requests Debugger Tool's Proxy will run\n"
17
+ + " Default: " + RdGlobalConfig . RD_HANDLER_PROXY_PORT + "\n"
18
+ + " --reverse-proxy-port <port> : Port on which the Requests Debugger Tool's Reverse Proxy will run\n"
19
+ + " Default: " + RdGlobalConfig . RD_HANDLER_REVERSE_PROXY_PORT + "\n"
20
+ + " --scheme <https/http> : Scheme for requests to browserstack.\n"
21
+ + " Default: " + RdGlobalConfig . SCHEME + "\n"
22
+ + " --proxy-host <hostname> : Hostname of the Upstream Proxy\n"
23
+ + " --proxy-port <port> : Port of the Upstream Proxy. Default: " + constants . DEFAULT_PROXY_PORT + " (if hostname is provided)\n"
24
+ + " --proxy-user <username> : Username for auth of the Upstream Proxy\n"
25
+ + " --proxy-pass <password> : Password for auth of the Upstream Proxy\n"
26
+ + " --retry-delay <milliseconds> : Delay for the retry of a failed request. Default: " + RdGlobalConfig . RETRY_DELAY + "ms\n"
27
+ + " --request-timeout <milliseconds> : Hard timeout for the requests being fired by the tool before receiving any response\n"
28
+ + " Default: " + RdGlobalConfig . CLIENT_REQ_TIMEOUT + "ms\n"
29
+ + " --logs-path <relative/absolute path> : Directory where the '" + constants . LOGS_FOLDER + "' folder will be created\n"
30
+ + " for storing logs. Default: Current Working Directory\n"
31
+ + " --del-logs : Deletes any existing logs from the " + constants . LOGS_FOLDER + "/ directory and initializes\n"
32
+ + " new files for logging\n"
33
+ + " --help : Help for Requests Debugger Tool\n"
34
+ + " --version : Version of the Requests Debugger Tool\n" ;
31
35
32
36
console . log ( helpOutput ) ;
33
37
} ,
@@ -38,7 +42,7 @@ var CommandLineManager = {
38
42
39
43
/**
40
44
* Processes the args from the given input array and sets the global config.
41
- * @param {Array<String> } argv
45
+ * @param {Array<String> } argv
42
46
*/
43
47
processArgs : function ( argv ) {
44
48
@@ -67,7 +71,7 @@ var CommandLineManager = {
67
71
if ( CommandLineManager . validArgValue ( argv [ index + 1 ] ) ) {
68
72
var probablePort = parseInt ( argv [ index + 1 ] ) ;
69
73
if ( ! isNaN ( probablePort ) && ( probablePort <= constants . PORTS . MAX ) && ( probablePort >= constants . PORTS . MIN ) ) {
70
- RdGlobalConfig . RD_HANDLER_PORT = probablePort ;
74
+ RdGlobalConfig . RD_HANDLER_PROXY_PORT = probablePort ;
71
75
} else {
72
76
console . log ( "\nPort can only range from:" , constants . PORTS . MIN , "to:" , constants . PORTS . MAX ) ;
73
77
invalidArgs . add ( '--port' ) ;
@@ -79,6 +83,24 @@ var CommandLineManager = {
79
83
}
80
84
}
81
85
86
+ // port for Requests Debugger Reverse Proxy
87
+ index = argv . indexOf ( '--reverse-proxy-port' ) ;
88
+ if ( index !== - 1 ) {
89
+ if ( CommandLineManager . validArgValue ( argv [ index + 1 ] ) ) {
90
+ var probableReverseProxyPort = parseInt ( argv [ index + 1 ] ) ;
91
+ if ( ! isNaN ( probableReverseProxyPort ) && ( probableReverseProxyPort <= constants . PORTS . MAX ) && ( probableReverseProxyPort >= constants . PORTS . MIN ) ) {
92
+ RdGlobalConfig . RD_HANDLER_REVERSE_PROXY_PORT = probableReverseProxyPort ;
93
+ } else {
94
+ console . log ( "\nPort can only range from:" , constants . PORTS . MIN , "to:" , constants . PORTS . MAX ) ;
95
+ invalidArgs . add ( '--reverse-proxy-port' ) ;
96
+ }
97
+ argv . splice ( index , 2 ) ;
98
+ } else {
99
+ invalidArgs . add ( '--reverse-proxy-port' ) ;
100
+ argv . splice ( index , 1 ) ;
101
+ }
102
+ }
103
+
82
104
// delay for retries in case of request failures
83
105
index = argv . indexOf ( '--retry-delay' ) ;
84
106
if ( index !== - 1 ) {
@@ -115,12 +137,34 @@ var CommandLineManager = {
115
137
}
116
138
}
117
139
140
+ // process proxy host
141
+ index = argv . indexOf ( '--scheme' ) ;
142
+ if ( index !== - 1 ) {
143
+ if ( CommandLineManager . validArgValue ( argv [ index + 1 ] ) ) {
144
+ var scheme = argv [ index + 1 ] ;
145
+ if ( ! ( scheme === 'http' || scheme === 'https' ) ) {
146
+ console . log ( "\nScheme can only be http/https" ) ;
147
+ invalidArgs . add ( '--scheme' ) ;
148
+ argv . splice ( index , 2 ) ;
149
+ }
150
+ else {
151
+ RdGlobalConfig . SCHEME = scheme ;
152
+ argv . splice ( index , 2 ) ;
153
+ }
154
+ } else {
155
+ invalidArgs . add ( '--scheme' ) ;
156
+ argv . splice ( index , 1 ) ;
157
+ }
158
+ }
159
+
118
160
// process proxy host
119
161
index = argv . indexOf ( '--proxy-host' ) ;
120
162
if ( index !== - 1 ) {
121
163
if ( CommandLineManager . validArgValue ( argv [ index + 1 ] ) ) {
122
164
var host = argv [ index + 1 ] ;
123
- host = host . replace ( constants . PROTOCOL_REGEX , '' ) ;
165
+ if ( host . lastIndexOf ( "http" ) !== 0 ) {
166
+ host = 'http://' + host ;
167
+ }
124
168
RdGlobalConfig . proxy = RdGlobalConfig . proxy || { } ;
125
169
RdGlobalConfig . proxy . host = host ;
126
170
argv . splice ( index , 2 ) ;
@@ -151,7 +195,7 @@ var CommandLineManager = {
151
195
argv . splice ( index , 1 ) ;
152
196
}
153
197
}
154
-
198
+
155
199
// if proxy port value in invalid or doesn't exist and host exists, set the default value
156
200
if ( RdGlobalConfig . proxy && RdGlobalConfig . proxy . host && ( invalidArgs . has ( '--proxy-port' ) || ! RdGlobalConfig . proxy . port ) ) {
157
201
console . log ( '\nSetting Default Proxy Port:' , constants . DEFAULT_PROXY_PORT , '\n' ) ;
@@ -190,7 +234,7 @@ var CommandLineManager = {
190
234
argv . splice ( index , 1 ) ;
191
235
}
192
236
}
193
-
237
+
194
238
// if proxy pass is invalid or doesn't exist and username exists, set the password as empty
195
239
if ( RdGlobalConfig . proxy && RdGlobalConfig . proxy . username && ( invalidArgs . has ( '--proxy-pass' ) || ! RdGlobalConfig . proxy . password ) ) {
196
240
console . log ( 'Setting Proxy Password as Empty\n' ) ;
0 commit comments