Skip to content

Commit e599151

Browse files
committed
[docs] upgrade UPGRADING.md
1 parent 162a42f commit e599151

File tree

1 file changed

+75
-5
lines changed

1 file changed

+75
-5
lines changed

UPGRADING.md

+75-5
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,96 @@
1-
`caronte` is a from-scratch implementation of `http-proxy` and, as such
1+
Looking to upgrade from `[email protected]` to `[email protected]`? You've come to the right place!
2+
`[email protected]` is a from-scratch implementation of `http-proxy` and, as such
23
brings some breaking changes to APIs.
34

45
## Server creation
56

67
Available through `.createServer()` or `.createProxyServer()`.
7-
Check the README.md for a more detailed explanation of the parameters.
8+
9+
```javascript
10+
httpProxy.createServer({
11+
target:'http://localhost:9003'
12+
}).listen(8003);
13+
```
14+
15+
Check the [README.md](https://github.com/nodejitsu/node-http-proxy/blob/caronte/README.md) for a more detailed explanation of the parameters.
816

917
## Proxying
1018

11-
Web proying is done by calling the `.web()` method on a Proxy instance. Websockets
12-
are proxied by the `.ws()` method.
19+
Web proying is done by calling the `.web()` method on a Proxy instance. You can check among some use cases in the [examples folder](https://github.com/nodejitsu/node-http-proxy/tree/caronte/examples/http)
20+
21+
```javascript
22+
//
23+
// Create a HTTP Proxy server with a HTTPS target
24+
//
25+
httpProxy.createProxyServer({
26+
target: 'https://google.com',
27+
agent : https.globalAgent,
28+
headers: {
29+
host: 'google.com'
30+
}
31+
}).listen(8011);
32+
33+
```
34+
35+
Websockets are proxied by the `.ws()` method. The [examples folder](https://github.com/nodejitsu/node-http-proxy/tree/caronte/examples/websocket) again provides a lot of useful snippets!
36+
37+
```javascript
38+
var proxy = new httpProxy.createProxyServer({
39+
target: {
40+
host: 'localhost',
41+
port: 9015
42+
}
43+
});
44+
var proxyServer = http.createServer(function (req, res) {
45+
proxy.web(req, res);
46+
});
47+
48+
//
49+
// Listen to the `upgrade` event and proxy the
50+
// WebSocket requests as well.
51+
//
52+
proxyServer.on('upgrade', function (req, socket, head) {
53+
proxy.ws(req, socket, head);
54+
});
55+
```
1356

1457
## Error Handling
1558

1659
It is possible to listen globally on the `error` event on the server. In alternative, a
1760
callback passed to `.web()` or `.ws()` as last parameter is also accepted.
1861

62+
```javascript
63+
var proxy = httpProxy.createServer({
64+
target:'http://localhost:9005'
65+
});
66+
67+
//
68+
// Tell the proxy to listen on port 8000
69+
//
70+
proxy.listen(8005);
71+
72+
//
73+
// Listen for the `error` event on `proxy`.
74+
proxy.on('error', function (err, req, res) {
75+
res.writeHead(500, {
76+
'Content-Type': 'text/plain'
77+
});
78+
79+
res.end('Something went wrong. And we are reporting a custom error message.');
80+
});
81+
```
82+
1983
## Dropped
2084

2185
Since the API was rewritten to be extremely flexible we decided to drop some features
22-
which were in the core and delegate them to eventual "user-land" modules.
86+
which were in the core and delegate them to eventual "userland" modules.
2387

2488
- Middleware API
2589
- ProxyTable API
2690

91+
### Middleware API
92+
93+
The new API makes it really easy to implement code that behaves like the old Middleware API. You can check some examples [here](https://github.com/nodejitsu/node-http-proxy/tree/caronte/examples/middleware)
94+
95+
96+

0 commit comments

Comments
 (0)