Skip to content

chore(prettier): use prettier2 #418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ const options = {
ws: true, // proxy websockets
pathRewrite: {
'^/api/old-path': '/api/new-path', // rewrite path
'^/api/remove/path': '/path' // remove base path
'^/api/remove/path': '/path', // remove base path
},
router: {
// when request.headers.host == 'dev.localhost:3000',
// override target 'http://www.example.org' to 'http://localhost:8000'
'dev.localhost:3000': 'http://localhost:8000'
}
'dev.localhost:3000': 'http://localhost:8000',
},
};

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

const apiProxy = createProxyMiddleware(filter, {
target: 'http://www.example.org'
target: 'http://www.example.org',
});
```

Expand Down Expand Up @@ -285,7 +285,7 @@ Providing an alternative way to decide which requests should be proxied; In case
debug: logger.debug,
info: logger.info,
warn: logger.warn,
error: logger.error
error: logger.error,
};
return myCustomProvider;
}
Expand All @@ -300,7 +300,7 @@ Subscribe to [http-proxy events](https://github.com/nodejitsu/node-http-proxy#li
```javascript
function onError(err, req, res) {
res.writeHead(500, {
'Content-Type': 'text/plain'
'Content-Type': 'text/plain',
});
res.end('Something went wrong. And we are reporting a custom error message.');
}
Expand Down Expand Up @@ -417,7 +417,7 @@ The following options are provided by the underlying [http-proxy](https://github
res,
{
target: 'http://localhost:4003/',
buffer: streamify(req.rawBody)
buffer: streamify(req.rawBody),
},
next
);
Expand Down
6 changes: 3 additions & 3 deletions examples/browser-sync/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { createProxyMiddleware } = require('../../dist'); // require('http-proxy-
const jsonPlaceholderProxy = createProxyMiddleware('/users', {
target: 'http://jsonplaceholder.typicode.com',
changeOrigin: true, // for vhosted sites, changes host header to match to target's host
logLevel: 'debug'
logLevel: 'debug',
});

/**
Expand All @@ -20,9 +20,9 @@ browserSync.init({
server: {
baseDir: './',
port: 3000,
middleware: [jsonPlaceholderProxy]
middleware: [jsonPlaceholderProxy],
},
startPath: '/users'
startPath: '/users',
});

console.log('[DEMO] Server: listening on port 3000');
Expand Down
2 changes: 1 addition & 1 deletion examples/connect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { createProxyMiddleware } = require('../../dist'); // require('http-proxy-
const jsonPlaceholderProxy = createProxyMiddleware({
target: 'http://jsonplaceholder.typicode.com',
changeOrigin: true, // for vhosted sites, changes host header to match to target's host
logLevel: 'debug'
logLevel: 'debug',
});

const app = connect();
Expand Down
2 changes: 1 addition & 1 deletion examples/express/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { createProxyMiddleware } = require('../../dist'); // require('http-proxy-
const jsonPlaceholderProxy = createProxyMiddleware({
target: 'http://jsonplaceholder.typicode.com',
changeOrigin: true, // for vhosted sites, changes host header to match to target's host
logLevel: 'debug'
logLevel: 'debug',
});

const app = express();
Expand Down
2 changes: 1 addition & 1 deletion examples/websocket/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const wsProxy = createProxyMiddleware('/', {
// },
changeOrigin: true, // for vhosted sites, changes host header to match to target's host
ws: true, // enable websocket proxy
logLevel: 'debug'
logLevel: 'debug',
});

const app = express();
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node'
testEnvironment: 'node',
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"lint-staged": "^10.0.7",
"mockttp": "^0.19.3",
"open": "^7.0.2",
"prettier": "^1.19.1",
"prettier": "^2.0.2",
"supertest": "^4.0.2",
"ts-jest": "^25.2.0",
"tslint": "^6.0.0",
Expand Down
14 changes: 7 additions & 7 deletions recipes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ const options = {

// additional request headers
headers: {
'x-powered-by': 'foobar'
'x-powered-by': 'foobar',
},

// rewrite paths
pathRewrite: {
'^/api/old-path': '/api/new-path', // rewrite path
'^/api/remove/path': '/path' // remove base path
'^/api/remove/path': '/path', // remove base path
},

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

// control logging
logLevel: 'silent',

// use a different lib for logging;
// i.e., write logs to file or server
logProvider: function(provider) {
logProvider: function (provider) {
return winston;
},

Expand All @@ -67,16 +67,16 @@ const options = {
},

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

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

/**
* The following options are provided by Nodejitsu's http-proxy
Expand Down
10 changes: 5 additions & 5 deletions recipes/context-matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This will match paths starting with `/api`
const { createProxyMiddleware } = require('http-proxy-middleware');

const apiProxy = createProxyMiddleware('/api', {
target: 'http://localhost:3000'
target: 'http://localhost:3000',
});

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

const apiProxy = createProxyMiddleware('/api/**/*.json', {
target: 'http://localhost:3000'
target: 'http://localhost:3000',
});
```

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

const apiProxy = createProxyMiddleware(['/api/**/*.json', '/rest/**'], {
target: 'http://localhost:3000'
target: 'http://localhost:3000',
});
```

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

const apiProxy = createProxyMiddleware(['foo/*.js', '!bar.js'], {
target: 'http://localhost:3000'
target: 'http://localhost:3000',
});
```

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

const filter = function(pathname, req) {
const filter = function (pathname, req) {
return pathname.match('^/api') && req.method === 'GET';
};

Expand Down
2 changes: 1 addition & 1 deletion recipes/corporate-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const proxyServer = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;

const options = {
target: 'http://localhost:3000',
agent: new HttpsProxyAgent(proxyServer)
agent: new HttpsProxyAgent(proxyServer),
};

const apiProxy = createProxyMiddleware('/api', options);
Expand Down
8 changes: 4 additions & 4 deletions recipes/delay.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ For achieving it just put additional route handler to your app before proxy hand
```javascript
const myProxy = createProxyMiddleware({
target: 'http://www.example.com',
changeOrigin: true
changeOrigin: true,
});

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

// Delay response completion by 5 seconds
const endOriginal = res.end;
res.end = function(...args) {
setTimeout(function() {
res.end = function (...args) {
setTimeout(function () {
endOriginal.apply(res, args);
}, 5000);
};
Expand Down
6 changes: 3 additions & 3 deletions recipes/https.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { createProxyMiddleware } = require('http-proxy-middleware');

const apiProxy = createProxyMiddleware('/api', {
target: 'https://example.org',
changeOrigin: true
changeOrigin: true,
});
```

Expand All @@ -27,8 +27,8 @@ const apiProxy = createProxyMiddleware('/api', {
host: 'example.org',
port: 443,
pfx: fs.readFileSync('path/to/certificate.p12'),
passphrase: 'password'
passphrase: 'password',
},
changeOrigin: true
changeOrigin: true,
});
```
4 changes: 2 additions & 2 deletions recipes/logLevel.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const { createProxyMiddleware } = require('http-proxy-middleware');

const options = {
target: 'http://localhost:3000',
logLevel: 'debug'
logLevel: 'debug',
};

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

const options = {
target: 'http://localhost:3000',
logLevel: 'silent'
logLevel: 'silent',
};

const apiProxy = createProxyMiddleware('/api', options);
Expand Down
18 changes: 9 additions & 9 deletions recipes/logProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const { createProxyMiddleware } = require('http-proxy-middleware');

const options = {
target: 'http://localhost:3000',
logProvider: function(provider) {
logProvider: function (provider) {
return winston;
}
},
};

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

const logProvider = function(provider) {
const logProvider = function (provider) {
return {
log: winston.log,
debug: winston.debug,
info: winston.info,
warn: winston.warn,
error: winston.error
error: winston.error,
};
};

const options = {
target: 'http://localhost:3000',
logProvider: logProvider
logProvider: logProvider,
};

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

const logProvider = function(provider) {
const logProvider = function (provider) {
const logger = new winston.Logger({
transports: [
new winston.transports.Console(),
new winston.transports.File({ filename: 'somefile.log' })
]
new winston.transports.File({ filename: 'somefile.log' }),
],
});

return logger;
};

const options = {
target: 'http://localhost:3000',
logProvider: logProvider
logProvider: logProvider,
};

const apiProxy = createProxyMiddleware('/api', options);
Expand Down
12 changes: 6 additions & 6 deletions recipes/modify-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const router = express.Router();

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

const proxy_options = {
target: 'http://localhost:8080',
pathRewrite: {
'^/docs': '/java/rep/server1' // Host path & target path conversion
'^/docs': '/java/rep/server1', // Host path & target path conversion
},
onError(err, req, res) {
res.writeHead(500, {
'Content-Type': 'text/plain'
'Content-Type': 'text/plain',
});
res.end('Something went wrong. And we are reporting a custom error message.' + err);
},
Expand All @@ -49,7 +49,7 @@ const proxy_options = {

// URI encode JSON object
body = Object.keys(body)
.map(function(key) {
.map(function (key) {
return encodeURIComponent(key) + '=' + encodeURIComponent(body[key]);
})
.join('&');
Expand All @@ -62,14 +62,14 @@ const proxy_options = {
proxyReq.write(body);
proxyReq.end();
}
}
},
};

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

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

Expand Down
Loading