@@ -24,52 +24,58 @@ At its simplest, the following will instantiate a non-authenticating transparent
24
24
proxy that forwards requests to the target url without relaying the request
25
25
through a third-party proxy:
26
26
27
- var RelayProxy = require('./path/to/relay-proxy');
28
- var server = new RelayProxy();
29
- server.listen(3333);
27
+ ``` js
28
+ var RelayProxy = require (' ./path/to/relay-proxy' );
29
+ var server = new RelayProxy ();
30
+ server .listen (3333 );
31
+ ```
30
32
31
33
### Local authorization
32
34
33
35
To authorize access to your proxy, provide a handler function:
34
36
35
- var RelayProxy = require('./path/to/relay-proxy');
36
- var server = new RelayProxy();
37
-
38
- server.authorize(function(req, username, password, callback) {
39
- // replace with code to verify username and password
40
- var isLoginCorrect = true;
41
-
42
- // call the supplied callback function to continue the request
43
- callback(null, isLoginCorrect);
44
- });
37
+ ``` js
38
+ var RelayProxy = require (' ./path/to/relay-proxy' );
39
+ var server = new RelayProxy ();
40
+
41
+ server .authorize (function (req , username , password , callback ) {
42
+ // replace with code to verify username and password
43
+ var isLoginCorrect = true ;
45
44
46
- server.listen(3333);
45
+ // call the supplied callback function to continue the request
46
+ callback (null , isLoginCorrect);
47
+ });
48
+ ```
49
+
50
+ server.listen(3333);
47
51
48
52
### Using a remote proxy
49
53
50
54
To forward requests via a third-party proxy, provide a handler function:
51
55
52
- var RelayProxy = require('./path/to/relay-proxy');
53
- var server = new RelayProxy();
56
+ ``` js
57
+ var RelayProxy = require (' ./path/to/relay-proxy' );
58
+ var server = new RelayProxy ();
59
+
60
+ server .selectForwardProxy (function (req , username , callback ) {
54
61
55
- server.selectForwardProxy(function(req, username, callback) {
56
-
57
- var proxy = {
58
- host: '1.2.3.4',
59
- port: 31337,
60
- username: 'jimbob', // only supply a username and password if
61
- password: 'mcgee' // the remote proxy requires authorization
62
- };
63
-
64
- // the callback's second argument can be one of three values:
65
- // null: no remote proxy - forward directly to the requested url
66
- // false: decline to forward the request (http 407 sent back to client)
67
- // proxy: proxy options as specified in the above sample
68
-
69
- callback(null, proxy);
70
- });
62
+ var proxy = {
63
+ host: ' 1.2.3.4' ,
64
+ port: 31337 ,
65
+ username: ' jimbob' , // only supply a username and password if
66
+ password: ' mcgee' // the remote proxy requires authorization
67
+ };
71
68
72
- server.listen(3333);
69
+ // the callback's second argument can be one of three values:
70
+ // null: no remote proxy - forward directly to the requested url
71
+ // false: decline to forward the request (http 407 sent back to client)
72
+ // proxy: proxy options as specified in the above sample
73
+
74
+ callback (null , proxy);
75
+ });
76
+
77
+ server .listen (3333 );
78
+ ```
73
79
74
80
## Dependencies
75
81
0 commit comments