You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13
Original file line number
Diff line number
Diff line change
@@ -23,11 +23,13 @@
23
23
Let's suppose you were running multiple http application servers, but you only wanted to expose one machine to the internet. You could setup node-http-proxy on that one machine and then reverse-proxy the incoming http requests to locally running services which were not exposed to the outside network.
24
24
25
25
### Installing npm (node package manager)
26
+
26
27
```
27
28
curl http://npmjs.org/install.sh | sh
28
29
```
29
30
30
31
### Installing node-http-proxy
32
+
31
33
```
32
34
npm install http-proxy
33
35
```
@@ -51,6 +53,7 @@ In each of these scenarios node-http-proxy can handle any of these types of requ
51
53
See the [examples][3] for more working sample code.
A Proxy Table is a simple lookup table that maps incoming requests to proxy target locations. Take a look at an example of the options you need to pass to httpProxy.createServer:
170
+
164
171
```js
165
172
var options = {
166
173
router: {
@@ -172,6 +179,7 @@ var options = {
172
179
```
173
180
174
181
The above route table will take incoming requests to 'foo.com/baz' and forward them to '127.0.0.1:8001'. Likewise it will take incoming requests to 'foo.com/buz' and forward them to '127.0.0.1:8002'. The routes themselves are later converted to regular expressions to enable more complex matching functionality. We can create a proxy server with these options by using the following code:
182
+
175
183
```js
176
184
var proxyServer =httpProxy.createServer(options);
177
185
proxyServer.listen(80);
@@ -194,6 +202,7 @@ Notice here that I have not included paths on the individual domains because thi
194
202
195
203
### Proxy requests with an additional forward proxy
196
204
Sometimes in addition to a reverse proxy, you may want your front-facing server to forward traffic to another location. For example, if you wanted to load test your staging environment. This is possible when using node-http-proxy using similar JSON-based configuration to a proxy table:
205
+
197
206
```js
198
207
var proxyServerWithForwarding =httpProxy.createServer(9000, 'localhost', {
199
208
forward: {
@@ -208,6 +217,7 @@ The forwarding option can be used in conjunction with the proxy table options by
208
217
209
218
### Using node-http-proxy from the command line
210
219
When you install this package with npm, a node-http-proxy binary will become available to you. Using this binary is easy with some simple options:
220
+
211
221
```js
212
222
usage: node-http-proxy [options]
213
223
@@ -223,6 +233,7 @@ options:
223
233
224
234
### Proxying over HTTPS
225
235
You have all the full flexibility of node-http-proxy offers in HTTPS as well as HTTP. The two basic scenarios are: with a stand-alone proxy server or in conjunction with another HTTPS server.
236
+
226
237
``` js
227
238
var fs = require('fs'),
228
239
https = require('https'),
@@ -263,6 +274,7 @@ https.createServer(options.https, function (req, res) {
263
274
264
275
### Proxying WebSockets
265
276
Websockets are handled automatically when using the `httpProxy.createServer()`, but if you want to use it in conjunction with a stand-alone HTTP + WebSocket (such as [socket.io][5]) server here's how:
If you have a suggestion for a feature currently not supported, feel free to open a [support issue][6]. node-http-proxy is designed to just proxy http requests from one server to another, but we will be soon releasing many other complimentary projects that can be used in conjunction with node-http-proxy.
0 commit comments