local-cors-proxy
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -13,3 +13,5 @@ #!/usr/bin/env node | ||
}, | ||
{ name: 'proxyUrl', type: String } | ||
{ name: 'proxyUrl', type: String }, | ||
{ name: 'credentials', type: Boolean, defaultValue: false }, | ||
{ name: 'origin', type: String, defaultValue: '*' } | ||
]; | ||
@@ -22,5 +24,5 @@ | ||
} | ||
lcp.startProxy(options.port, options.proxyUrl, options.proxyPartial); | ||
lcp.startProxy(options.port, options.proxyUrl, options.proxyPartial, options.credentials, options.origin); | ||
} catch (error) { | ||
console.error(error); | ||
} |
@@ -7,5 +7,5 @@ var express = require('express'); | ||
var startProxy = function(port, proxyUrl, proxyPartial) { | ||
proxy.use(cors()); | ||
proxy.options('*', cors()); | ||
var startProxy = function(port, proxyUrl, proxyPartial, credentials, origin) { | ||
proxy.use(cors({credentials: credentials, origin: origin})); | ||
proxy.options('*', cors({credentials: credentials, origin: origin})); | ||
@@ -21,3 +21,13 @@ // remove trailing slash | ||
} catch (e) {} | ||
req.pipe(request(cleanProxyUrl + req.url)).pipe(res); | ||
req.pipe( | ||
request(cleanProxyUrl + req.url) | ||
.on('response', response => { | ||
// In order to avoid https://github.com/expressjs/cors/issues/134 | ||
const accessControlAllowOriginHeader = response.headers['access-control-allow-origin'] | ||
if(accessControlAllowOriginHeader && accessControlAllowOriginHeader !== origin ){ | ||
console.log(chalk.blue('Override access-control-allow-origin header from proxified URL : ' + chalk.green(accessControlAllowOriginHeader) + '\n')); | ||
response.headers['access-control-allow-origin'] = origin; | ||
} | ||
}) | ||
).pipe(res); | ||
}); | ||
@@ -31,3 +41,5 @@ | ||
console.log(chalk.blue('Proxy Partial: ' + chalk.green(cleanProxyPartial))); | ||
console.log(chalk.blue('PORT: ' + chalk.green(port) + '\n')); | ||
console.log(chalk.blue('PORT: ' + chalk.green(port))); | ||
console.log(chalk.blue('Credentials: ' + chalk.green(credentials))); | ||
console.log(chalk.blue('Origin: ' + chalk.green(origin) + '\n')); | ||
console.log( | ||
@@ -34,0 +46,0 @@ chalk.cyan( |
{ | ||
"name": "local-cors-proxy", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"main": "./lib/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"start": "node ./bin/lcp.js", | ||
"test": "echo \"No tests specified\" && exit 0" | ||
}, | ||
@@ -17,3 +18,9 @@ "bin": { | ||
}, | ||
"keywords": ["cors", "proxy", "simple", "node", "express"], | ||
"keywords": [ | ||
"cors", | ||
"proxy", | ||
"simple", | ||
"node", | ||
"express" | ||
], | ||
"bugs": { | ||
@@ -20,0 +27,0 @@ "url": "https://github.com/garmeeh/local-cors-proxy/issues" |
@@ -54,1 +54,3 @@ # Local CORS Proxy | ||
| --port | 8010 | 8010 | | ||
| --credentials | (no value needed) | false | | ||
| --origin | http://localhost:4200 | * | |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
67
56
6098
5