Skip to content

Commit 91737fa

Browse files
committed
[doc] Update examples for HTTPS to HTTP proxying
1 parent 895f577 commit 91737fa

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

Diff for: examples/proxy-https-to-http.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
proxy-https-to-http.js: Basic example of proxying over HTTPS to a target HTTP server
3+
4+
Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining
7+
a copy of this software and associated documentation files (the
8+
"Software"), to deal in the Software without restriction, including
9+
without limitation the rights to use, copy, modify, merge, publish,
10+
distribute, sublicense, and/or sell copies of the Software, and to
11+
permit persons to whom the Software is furnished to do so, subject to
12+
the following conditions:
13+
14+
The above copyright notice and this permission notice shall be
15+
included in all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
25+
*/
26+
27+
var https = require('https'),
28+
http = require('http'),
29+
util = require('util'),
30+
colors = require('colors'),
31+
httpProxy = require('./../lib/node-http-proxy'),
32+
helpers = require('./../test/helpers');
33+
34+
var opts = helpers.loadHttps();
35+
36+
//
37+
// Crete the target HTTPS server
38+
//
39+
http.createServer(function (req, res) {
40+
res.writeHead(200, { 'Content-Type': 'text/plain' });
41+
res.write('hello http over https\n');
42+
res.end();
43+
}).listen(8000);
44+
45+
//
46+
// Create the proxy server listening on port 443.
47+
//
48+
httpProxy.createServer(8000, 'localhost', {
49+
https: opts
50+
}).listen(8080);
51+
52+
util.puts('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8080'.yellow);
53+
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow);

Diff for: examples/basic-proxy-https.js renamed to examples/proxy-https-to-https.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
basic-proxy-https.js: Basic example of proxying over HTTPS
2+
proxy-https-to-https.js: Basic example of proxying over HTTPS to a target HTTPS server
33
44
Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires.
55
@@ -45,9 +45,12 @@ https.createServer(opts, function (req, res) {
4545
//
4646
// Create the proxy server listening on port 443.
4747
//
48-
httpProxy.createServer(443, 'localhost', {
49-
https: opts
48+
httpProxy.createServer(8000, 'localhost', {
49+
https: opts,
50+
target: {
51+
https: true
52+
}
5053
}).listen(8080);
5154

52-
util.puts('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
53-
util.puts('https server '.blue + 'started '.green.bold + 'on port '.blue + '8080 '.yellow);
55+
util.puts('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8080'.yellow);
56+
util.puts('https server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow);

0 commit comments

Comments
 (0)