Skip to content

Commit 5e79b93

Browse files
authored
chore(prettier): use prettier2 (chimurai#418)
1 parent e767654 commit 5e79b93

39 files changed

+222
-237
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ const options = {
132132
ws: true, // proxy websockets
133133
pathRewrite: {
134134
'^/api/old-path': '/api/new-path', // rewrite path
135-
'^/api/remove/path': '/path' // remove base path
135+
'^/api/remove/path': '/path', // remove base path
136136
},
137137
router: {
138138
// when request.headers.host == 'dev.localhost:3000',
139139
// override target 'http://www.example.org' to 'http://localhost:8000'
140-
'dev.localhost:3000': 'http://localhost:8000'
141-
}
140+
'dev.localhost:3000': 'http://localhost:8000',
141+
},
142142
};
143143

144144
// create the proxy (without context)
@@ -194,12 +194,12 @@ Providing an alternative way to decide which requests should be proxied; In case
194194
/**
195195
* @return {Boolean}
196196
*/
197-
const filter = function(pathname, req) {
197+
const filter = function (pathname, req) {
198198
return pathname.match('^/api') && req.method === 'GET';
199199
};
200200

201201
const apiProxy = createProxyMiddleware(filter, {
202-
target: 'http://www.example.org'
202+
target: 'http://www.example.org',
203203
});
204204
```
205205

@@ -285,7 +285,7 @@ Providing an alternative way to decide which requests should be proxied; In case
285285
debug: logger.debug,
286286
info: logger.info,
287287
warn: logger.warn,
288-
error: logger.error
288+
error: logger.error,
289289
};
290290
return myCustomProvider;
291291
}
@@ -300,7 +300,7 @@ Subscribe to [http-proxy events](https://github.com/nodejitsu/node-http-proxy#li
300300
```javascript
301301
function onError(err, req, res) {
302302
res.writeHead(500, {
303-
'Content-Type': 'text/plain'
303+
'Content-Type': 'text/plain',
304304
});
305305
res.end('Something went wrong. And we are reporting a custom error message.');
306306
}
@@ -417,7 +417,7 @@ The following options are provided by the underlying [http-proxy](https://github
417417
res,
418418
{
419419
target: 'http://localhost:4003/',
420-
buffer: streamify(req.rawBody)
420+
buffer: streamify(req.rawBody),
421421
},
422422
next
423423
);

examples/browser-sync/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const { createProxyMiddleware } = require('../../dist'); // require('http-proxy-
1010
const jsonPlaceholderProxy = createProxyMiddleware('/users', {
1111
target: 'http://jsonplaceholder.typicode.com',
1212
changeOrigin: true, // for vhosted sites, changes host header to match to target's host
13-
logLevel: 'debug'
13+
logLevel: 'debug',
1414
});
1515

1616
/**
@@ -20,9 +20,9 @@ browserSync.init({
2020
server: {
2121
baseDir: './',
2222
port: 3000,
23-
middleware: [jsonPlaceholderProxy]
23+
middleware: [jsonPlaceholderProxy],
2424
},
25-
startPath: '/users'
25+
startPath: '/users',
2626
});
2727

2828
console.log('[DEMO] Server: listening on port 3000');

examples/connect/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { createProxyMiddleware } = require('../../dist'); // require('http-proxy-
1111
const jsonPlaceholderProxy = createProxyMiddleware({
1212
target: 'http://jsonplaceholder.typicode.com',
1313
changeOrigin: true, // for vhosted sites, changes host header to match to target's host
14-
logLevel: 'debug'
14+
logLevel: 'debug',
1515
});
1616

1717
const app = connect();

examples/express/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const { createProxyMiddleware } = require('../../dist'); // require('http-proxy-
1010
const jsonPlaceholderProxy = createProxyMiddleware({
1111
target: 'http://jsonplaceholder.typicode.com',
1212
changeOrigin: true, // for vhosted sites, changes host header to match to target's host
13-
logLevel: 'debug'
13+
logLevel: 'debug',
1414
});
1515

1616
const app = express();

examples/websocket/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const wsProxy = createProxyMiddleware('/', {
1515
// },
1616
changeOrigin: true, // for vhosted sites, changes host header to match to target's host
1717
ws: true, // enable websocket proxy
18-
logLevel: 'debug'
18+
logLevel: 'debug',
1919
});
2020

2121
const app = express();

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
preset: 'ts-jest',
3-
testEnvironment: 'node'
3+
testEnvironment: 'node',
44
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"lint-staged": "^10.0.7",
6969
"mockttp": "^0.19.3",
7070
"open": "^7.0.2",
71-
"prettier": "^1.19.1",
71+
"prettier": "^2.0.2",
7272
"supertest": "^4.0.2",
7373
"ts-jest": "^25.2.0",
7474
"tslint": "^6.0.0",

recipes/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ const options = {
3232

3333
// additional request headers
3434
headers: {
35-
'x-powered-by': 'foobar'
35+
'x-powered-by': 'foobar',
3636
},
3737

3838
// rewrite paths
3939
pathRewrite: {
4040
'^/api/old-path': '/api/new-path', // rewrite path
41-
'^/api/remove/path': '/path' // remove base path
41+
'^/api/remove/path': '/path', // remove base path
4242
},
4343

4444
// re-target based on the request's host header and/or path
@@ -48,15 +48,15 @@ const options = {
4848
'integration.localhost:8000': 'http://localhost:8001', // host only
4949
'staging.localhost:8000': 'http://localhost:8002', // host only
5050
'localhost:8000/api': 'http://localhost:8003', // host + path
51-
'/rest': 'http://localhost:8004' // path only
51+
'/rest': 'http://localhost:8004', // path only
5252
},
5353

5454
// control logging
5555
logLevel: 'silent',
5656

5757
// use a different lib for logging;
5858
// i.e., write logs to file or server
59-
logProvider: function(provider) {
59+
logProvider: function (provider) {
6060
return winston;
6161
},
6262

@@ -67,16 +67,16 @@ const options = {
6767
},
6868

6969
// subscribe to http-proxy's proxyRes event
70-
onProxyRes: function(proxyRes, req, res) {
70+
onProxyRes: function (proxyRes, req, res) {
7171
proxyRes.headers['x-added'] = 'foobar';
7272
delete proxyRes.headers['x-removed'];
7373
},
7474

7575
// subscribe to http-proxy's proxyReq event
76-
onProxyReq: function(proxyReq, req, res) {
76+
onProxyReq: function (proxyReq, req, res) {
7777
// add custom header to request
7878
proxyReq.setHeader('x-powered-by', 'foobar');
79-
}
79+
},
8080

8181
/**
8282
* The following options are provided by Nodejitsu's http-proxy

recipes/context-matching.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This will match paths starting with `/api`
3434
const { createProxyMiddleware } = require('http-proxy-middleware');
3535

3636
const apiProxy = createProxyMiddleware('/api', {
37-
target: 'http://localhost:3000'
37+
target: 'http://localhost:3000',
3838
});
3939

4040
// `/api/foo/bar` -> `http://localhost:3000/api/foo/bar`
@@ -61,7 +61,7 @@ This will match paths starting with `/api/` and should also end with `.json`
6161
const { createProxyMiddleware } = require('http-proxy-middleware');
6262

6363
const apiProxy = createProxyMiddleware('/api/**/*.json', {
64-
target: 'http://localhost:3000'
64+
target: 'http://localhost:3000',
6565
});
6666
```
6767

@@ -73,7 +73,7 @@ Multiple wildcards can be used.
7373
const { createProxyMiddleware } = require('http-proxy-middleware');
7474

7575
const apiProxy = createProxyMiddleware(['/api/**/*.json', '/rest/**'], {
76-
target: 'http://localhost:3000'
76+
target: 'http://localhost:3000',
7777
});
7878
```
7979

@@ -85,7 +85,7 @@ This example will create a proxy with wildcard context matching.
8585
const { createProxyMiddleware } = require('http-proxy-middleware');
8686

8787
const apiProxy = createProxyMiddleware(['foo/*.js', '!bar.js'], {
88-
target: 'http://localhost:3000'
88+
target: 'http://localhost:3000',
8989
});
9090
```
9191

@@ -97,7 +97,7 @@ The request `pathname` and `req` object are provided to determine which requests
9797
```javascript
9898
const { createProxyMiddleware } = require('http-proxy-middleware');
9999

100-
const filter = function(pathname, req) {
100+
const filter = function (pathname, req) {
101101
return pathname.match('^/api') && req.method === 'GET';
102102
};
103103

recipes/corporate-proxy.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const proxyServer = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
1313

1414
const options = {
1515
target: 'http://localhost:3000',
16-
agent: new HttpsProxyAgent(proxyServer)
16+
agent: new HttpsProxyAgent(proxyServer),
1717
};
1818

1919
const apiProxy = createProxyMiddleware('/api', options);

recipes/delay.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ For achieving it just put additional route handler to your app before proxy hand
1010
```javascript
1111
const myProxy = createProxyMiddleware({
1212
target: 'http://www.example.com',
13-
changeOrigin: true
13+
changeOrigin: true,
1414
});
1515

16-
const proxyDelay = function(req, res, next) {
16+
const proxyDelay = function (req, res, next) {
1717
if (req.originalUrl === '/api/get-me-something') {
1818
// Delay request by 2 seconds
1919
setTimeout(next, 2000);
2020

2121
// Delay response completion by 5 seconds
2222
const endOriginal = res.end;
23-
res.end = function(...args) {
24-
setTimeout(function() {
23+
res.end = function (...args) {
24+
setTimeout(function () {
2525
endOriginal.apply(res, args);
2626
}, 5000);
2727
};

recipes/https.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { createProxyMiddleware } = require('http-proxy-middleware');
1111

1212
const apiProxy = createProxyMiddleware('/api', {
1313
target: 'https://example.org',
14-
changeOrigin: true
14+
changeOrigin: true,
1515
});
1616
```
1717

@@ -27,8 +27,8 @@ const apiProxy = createProxyMiddleware('/api', {
2727
host: 'example.org',
2828
port: 443,
2929
pfx: fs.readFileSync('path/to/certificate.p12'),
30-
passphrase: 'password'
30+
passphrase: 'password',
3131
},
32-
changeOrigin: true
32+
changeOrigin: true,
3333
});
3434
```

recipes/logLevel.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const { createProxyMiddleware } = require('http-proxy-middleware');
1919

2020
const options = {
2121
target: 'http://localhost:3000',
22-
logLevel: 'debug'
22+
logLevel: 'debug',
2323
};
2424

2525
const apiProxy = createProxyMiddleware('/api', options);
@@ -34,7 +34,7 @@ const { createProxyMiddleware } = require('http-proxy-middleware');
3434

3535
const options = {
3636
target: 'http://localhost:3000',
37-
logLevel: 'silent'
37+
logLevel: 'silent',
3838
};
3939

4040
const apiProxy = createProxyMiddleware('/api', options);

recipes/logProvider.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ const { createProxyMiddleware } = require('http-proxy-middleware');
1010

1111
const options = {
1212
target: 'http://localhost:3000',
13-
logProvider: function(provider) {
13+
logProvider: function (provider) {
1414
return winston;
15-
}
15+
},
1616
};
1717

1818
const apiProxy = createProxyMiddleware('/api', options);
@@ -28,19 +28,19 @@ In this example [winston](https://www.npmjs.com/package/winston) is configured t
2828
const winston = require('winston');
2929
const { createProxyMiddleware } = require('http-proxy-middleware');
3030

31-
const logProvider = function(provider) {
31+
const logProvider = function (provider) {
3232
return {
3333
log: winston.log,
3434
debug: winston.debug,
3535
info: winston.info,
3636
warn: winston.warn,
37-
error: winston.error
37+
error: winston.error,
3838
};
3939
};
4040

4141
const options = {
4242
target: 'http://localhost:3000',
43-
logProvider: logProvider
43+
logProvider: logProvider,
4444
};
4545

4646
const apiProxy = createProxyMiddleware('/api', options);
@@ -56,20 +56,20 @@ In this example [winston](https://www.npmjs.com/package/winston) is configured t
5656
const winston = require('winston');
5757
const { createProxyMiddleware } = require('http-proxy-middleware');
5858

59-
const logProvider = function(provider) {
59+
const logProvider = function (provider) {
6060
const logger = new winston.Logger({
6161
transports: [
6262
new winston.transports.Console(),
63-
new winston.transports.File({ filename: 'somefile.log' })
64-
]
63+
new winston.transports.File({ filename: 'somefile.log' }),
64+
],
6565
});
6666

6767
return logger;
6868
};
6969

7070
const options = {
7171
target: 'http://localhost:3000',
72-
logProvider: logProvider
72+
logProvider: logProvider,
7373
};
7474

7575
const apiProxy = createProxyMiddleware('/api', options);

recipes/modify-post.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ const express = require('express');
1616
const { createProxyMiddleware } = require('http-proxy-middleware');
1717
const router = express.Router();
1818

19-
const proxy_filter = function(path, req) {
19+
const proxy_filter = function (path, req) {
2020
return path.match('^/docs') && (req.method === 'GET' || req.method === 'POST');
2121
};
2222

2323
const proxy_options = {
2424
target: 'http://localhost:8080',
2525
pathRewrite: {
26-
'^/docs': '/java/rep/server1' // Host path & target path conversion
26+
'^/docs': '/java/rep/server1', // Host path & target path conversion
2727
},
2828
onError(err, req, res) {
2929
res.writeHead(500, {
30-
'Content-Type': 'text/plain'
30+
'Content-Type': 'text/plain',
3131
});
3232
res.end('Something went wrong. And we are reporting a custom error message.' + err);
3333
},
@@ -49,7 +49,7 @@ const proxy_options = {
4949

5050
// URI encode JSON object
5151
body = Object.keys(body)
52-
.map(function(key) {
52+
.map(function (key) {
5353
return encodeURIComponent(key) + '=' + encodeURIComponent(body[key]);
5454
})
5555
.join('&');
@@ -62,14 +62,14 @@ const proxy_options = {
6262
proxyReq.write(body);
6363
proxyReq.end();
6464
}
65-
}
65+
},
6666
};
6767

6868
// Proxy configuration
6969
const proxy = createProxyMiddleware(proxy_filter, proxy_options);
7070

7171
/* GET home page. */
72-
router.get('/', function(req, res, next) {
72+
router.get('/', function (req, res, next) {
7373
res.render('index', { title: 'Node.js Express Proxy Test' });
7474
});
7575

0 commit comments

Comments
 (0)