Skip to content

Commit 777b911

Browse files
authored
Merge pull request #399 from chimurai/docs-polka
docs(polka): add polka example usage
2 parents b8f3321 + 41534b9 commit 777b911

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

Diff for: README.md

+17-11
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ _All_ `http-proxy` [options](https://github.com/nodejitsu/node-http-proxy#option
6060

6161
## Install
6262

63-
```javascript
63+
```bash
6464
$ npm install --save-dev http-proxy-middleware
6565
```
6666

@@ -136,7 +136,7 @@ Providing an alternative way to decide which requests should be proxied; In case
136136

137137
[RFC 3986 `path`](https://tools.ietf.org/html/rfc3986#section-3.3) is used for context matching.
138138

139-
```
139+
```ascii
140140
foo://example.com:8042/over/there?name=ferret#nose
141141
\_/ \______________/\_________/ \_________/ \__/
142142
| | | | |
@@ -316,6 +316,7 @@ Subscribe to [http-proxy events](https://github.com/nodejitsu/node-http-proxy#li
316316
```
317317

318318
- **option.onClose**: function, subscribe to http-proxy's `close` event.
319+
319320
```javascript
320321
function onClose(res, socket, head) {
321322
// view disconnected websocket connections
@@ -349,7 +350,7 @@ The following options are provided by the underlying [http-proxy](https://github
349350
- String: new domain, for example `cookieDomainRewrite: "new.domain"`. To remove the domain, use `cookieDomainRewrite: ""`.
350351
- Object: mapping of domains to new domains, use `"*"` to match all domains.
351352
For example keep one domain unchanged, rewrite one domain and remove other domains:
352-
```
353+
```json
353354
cookieDomainRewrite: {
354355
"unchanged.domain": "unchanged.domain",
355356
"old.domain": "new.domain",
@@ -361,7 +362,7 @@ The following options are provided by the underlying [http-proxy](https://github
361362
- String: new path, for example `cookiePathRewrite: "/newPath/"`. To remove the path, use `cookiePathRewrite: ""`. To set path to root use `cookiePathRewrite: "/"`.
362363
- Object: mapping of paths to new paths, use `"*"` to match all paths.
363364
For example, to keep one path unchanged, rewrite one path and remove other paths:
364-
```
365+
```json
365366
cookiePathRewrite: {
366367
"/unchanged.path/": "/unchanged.path/",
367368
"/old.path/": "/new.path/",
@@ -375,20 +376,23 @@ The following options are provided by the underlying [http-proxy](https://github
375376
- **option.selfHandleResponse** true/false, if set to true, none of the webOutgoing passes are called and it's your responsibility to appropriately return the response by listening and acting on the `proxyRes` event
376377
- **option.buffer**: stream of data to send as the request body. Maybe you have some middleware that consumes the request stream before proxying it on e.g. If you read the body of a request into a field called 'req.rawbody' you could restream this field in the buffer option:
377378

378-
```
379+
```javascript
379380
'use strict';
380381

381382
const streamify = require('stream-array');
382383
const HttpProxy = require('http-proxy');
383384
const proxy = new HttpProxy();
384385

385386
module.exports = (req, res, next) => {
386-
387-
proxy.web(req, res, {
388-
target: 'http://localhost:4003/',
389-
buffer: streamify(req.rawBody)
390-
}, next);
391-
387+
proxy.web(
388+
req,
389+
res,
390+
{
391+
target: 'http://localhost:4003/',
392+
buffer: streamify(req.rawBody)
393+
},
394+
next
395+
);
392396
};
393397
```
394398

@@ -423,6 +427,7 @@ app.use(
423427

424428
- express: http://expressjs.com/en/4x/api.html#app.use
425429
- connect: https://github.com/senchalabs/connect#mount-middleware
430+
- polka: https://github.com/lukeed/polka#usebase-fn
426431

427432
## WebSocket
428433

@@ -472,6 +477,7 @@ View the [recipes](https://github.com/chimurai/http-proxy-middleware/tree/master
472477
- [express](https://www.npmjs.com/package/express)
473478
- [browser-sync](https://www.npmjs.com/package/browser-sync)
474479
- [lite-server](https://www.npmjs.com/package/lite-server)
480+
- [polka](https://github.com/lukeed/polka)
475481
- [grunt-contrib-connect](https://www.npmjs.com/package/grunt-contrib-connect)
476482
- [grunt-browser-sync](https://www.npmjs.com/package/grunt-browser-sync)
477483
- [gulp-connect](https://www.npmjs.com/package/gulp-connect)

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"https",
3636
"connect",
3737
"express",
38+
"polka",
3839
"browser-sync",
3940
"gulp",
4041
"grunt-contrib-connect",

Diff for: recipes/servers.md

+24-2
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ Overview of `http-proxy-middleware` implementation in different servers.
44

55
Missing a server? Feel free to extend this list of examples.
66

7-
<!-- MarkdownTOC autolink=true bracket=round -->
7+
<!-- TOC depthfrom:2 insertanchor:false -->
88

99
- [Browser-Sync](#browser-sync)
1010
- [Express](#express)
1111
- [Connect](#connect)
1212
- [lite-server](#lite-server)
13+
- [Polka](#polka)
1314
- [grunt-contrib-connect](#grunt-contrib-connect)
1415
- [grunt-browser-sync](#grunt-browser-sync)
1516
- [gulp-connect](#gulp-connect)
1617
- [gulp-webserver](#gulp-webserver)
1718

18-
<!-- /MarkdownTOC -->
19+
<!-- /TOC -->
1920

2021
## Browser-Sync
2122

@@ -109,6 +110,27 @@ module.exports = {
109110
};
110111
```
111112

113+
## Polka
114+
115+
https://github.com/lukeed/polka
116+
[![GitHub stars](https://img.shields.io/github/stars/lukeed/polka.svg?style=social&label=Star)](https://github.com/lukeed/polka)
117+
118+
```javascript
119+
const polka = require('polka');
120+
const proxy = require('http-proxy-middleware');
121+
122+
const app = polka();
123+
124+
app.use(
125+
proxy({
126+
target: 'http://www.example.org',
127+
changeOrigin: true
128+
})
129+
);
130+
131+
app.listen(3000);
132+
```
133+
112134
## grunt-contrib-connect
113135

114136
https://github.com/gruntjs/grunt-contrib-connect

0 commit comments

Comments
 (0)