local-cors-proxy
Advanced tools
Comparing version 1.0.1 to 1.0.2
var express = require('express'); | ||
var request = require('request'); | ||
var cors = require('cors'); | ||
var chalk = require('chalk'); | ||
var proxy = express(); | ||
@@ -9,13 +10,30 @@ | ||
proxy.options('*', cors()); | ||
// remove trailing slash | ||
var cleanProxyUrl = proxyUrl.replace(/\/$/, ''); | ||
// remove all forward slashes | ||
var cleanProxyPartial = proxyPartial.replace(/\//g, ''); | ||
proxy.use('/' + cleanProxyPartial, function(req, res) { | ||
// remove trailing slash | ||
var cleanProxyUrl = proxyUrl.replace(/\/$/, ''); | ||
req.pipe(request(proxyUrl + req.url)).pipe(res); | ||
try { | ||
console.log(chalk.green('Request Proxied -> ' + req.url)); | ||
} catch (e) {} | ||
req.pipe(request(cleanProxyUrl + req.url)).pipe(res); | ||
}); | ||
proxy.listen(port); | ||
console.log('Proxy Active'); | ||
// Welcome Message | ||
console.log(chalk.bgGreen.black.bold.underline('\n Proxy Active \n')); | ||
console.log(chalk.blue('Proxy Url: ' + chalk.green(cleanProxyUrl))); | ||
console.log(chalk.blue('Proxy Partial: ' + chalk.green(cleanProxyPartial))); | ||
console.log(chalk.blue('PORT: ' + chalk.green(port) + '\n')); | ||
console.log( | ||
chalk.cyan( | ||
'To start using the proxy simply replace the proxied part of your url with: ' + | ||
chalk.bold('http://localhost:' + port + '/' + cleanProxyPartial + '\n') | ||
) | ||
); | ||
}; | ||
exports.startProxy = startProxy; |
{ | ||
"name": "local-cors-proxy", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"main": "./lib/index.js", | ||
@@ -23,2 +23,3 @@ "scripts": { | ||
"dependencies": { | ||
"chalk": "^2.3.2", | ||
"command-line-args": "^5.0.2", | ||
@@ -25,0 +26,0 @@ "cors": "^2.8.4", |
@@ -39,8 +39,16 @@ # Local CORS Proxy | ||
Alternatively you can install the package locally and add a script to your project: | ||
```json | ||
"scripts": { | ||
"proxy": "lcp --proxyUrl https://www.yourdomain.ie" | ||
} | ||
``` | ||
## Options | ||
| Option | Example | Default | | ||
| -------------- | -------------------- | ------: | | ||
| --proxyUrl | http://www.google.ie | | | ||
| --proxyPartial | foo | proxy | | ||
| --port | 8010 | 8010 | | ||
| Option | Example | Default | | ||
| -------------- | --------------------- | ------: | | ||
| --proxyUrl | https://www.google.ie | | | ||
| --proxyPartial | foo | proxy | | ||
| --port | 8010 | 8010 | |
Sorry, the diff of this file is not supported yet
27290
53
54
5
+ Addedchalk@^2.3.2
+ Addedansi-styles@3.2.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)