@podium/proxy
Advanced tools
Comparing version 5.0.0-next.3 to 5.0.0-next.4
@@ -0,1 +1,15 @@ | ||
# [5.0.0-next.4](https://github.com/podium-lib/proxy/compare/v5.0.0-next.3...v5.0.0-next.4) (2020-07-29) | ||
### Features | ||
* Use ES private properties instead of Symbols and defineProperty() for privacy ([#84](https://github.com/podium-lib/proxy/issues/84)) ([37fd140](https://github.com/podium-lib/proxy/commit/37fd1406975a046e0f79b50858c04bd13ca46ba0)) | ||
### BREAKING CHANGES | ||
* Due to dropping node 10.x support we use ES private properties instead of Symbols and `.defineProperty()`. | ||
Co-authored-by: Trygve Lie <trygve.lie@finn.no> | ||
# [5.0.0-next.3](https://github.com/podium-lib/proxy/compare/v5.0.0-next.2...v5.0.0-next.3) (2020-07-15) | ||
@@ -2,0 +16,0 @@ |
139
lib/proxy.js
@@ -13,2 +13,11 @@ 'use strict'; | ||
const PodiumProxy = class PodiumProxy { | ||
#pathname; | ||
#prefix; | ||
#log; | ||
#registry; | ||
#proxy; | ||
#metrics; | ||
#histogram; | ||
#pathnameEntries; | ||
#pathnameParser; | ||
constructor({ | ||
@@ -21,59 +30,22 @@ pathname = '/', | ||
} = {}) { | ||
Object.defineProperty(this, 'pathname', { | ||
enumerable: true, | ||
value: utils.pathnameBuilder(pathname), | ||
}); | ||
this.#pathname = utils.pathnameBuilder(pathname); | ||
this.#prefix = utils.pathnameBuilder(prefix); | ||
this.#log = abslog(logger); | ||
Object.defineProperty(this, 'prefix', { | ||
enumerable: true, | ||
value: utils.pathnameBuilder(prefix), | ||
}); | ||
Object.defineProperty(this, 'log', { | ||
value: abslog(logger), | ||
}); | ||
Object.defineProperty(this, 'registry', { | ||
value: new Cache({ | ||
ttl: maxAge, | ||
}), | ||
}); | ||
this.registry.on('error', (error) => { | ||
this.log.error( | ||
'Error emitted by the registry in @podium/proxy module', | ||
error, | ||
); | ||
}); | ||
Object.defineProperty(this, 'proxy', { | ||
// eslint-disable-next-line new-cap | ||
value: new Proxy.createProxy({ | ||
proxyTimeout: timeout, | ||
}), | ||
}); | ||
Object.defineProperty(this, 'metrics', { | ||
enumerable: true, | ||
value: new Metrics(), | ||
}); | ||
Object.defineProperty(this, 'pathnameEntries', { | ||
value: [], | ||
}); | ||
const regExPath = utils.pathnameBuilder( | ||
this.pathname, | ||
this.prefix, | ||
this.#pathnameEntries = []; | ||
this.#pathnameParser = pathToRegexp(utils.pathnameBuilder( | ||
this.#pathname, | ||
this.#prefix, | ||
':podiumPodletName', | ||
':podiumProxyName', | ||
':podiumProxyExtras*', | ||
); | ||
Object.defineProperty(this, 'pathnameParser', { | ||
value: pathToRegexp(regExPath, this.pathnameEntries), | ||
), this.#pathnameEntries); | ||
// eslint-disable-next-line new-cap | ||
this.#proxy = new Proxy.createProxy({ | ||
proxyTimeout: timeout, | ||
}); | ||
this.metrics.on('error', (error) => { | ||
this.log.error( | ||
'Error emitted by metric stream in @podium/proxy module', | ||
this.#proxy.on('error', (error) => { | ||
this.#log.error( | ||
'Error emitted by proxy in @podium/proxy module', | ||
error, | ||
@@ -83,18 +55,20 @@ ); | ||
this.proxy.on('error', (error) => { | ||
this.log.error( | ||
'Error emitted by proxy in @podium/proxy module', | ||
this.#registry = new Cache({ | ||
ttl: maxAge, | ||
}); | ||
this.#registry.on('error', (error) => { | ||
this.#log.error( | ||
'Error emitted by the registry in @podium/proxy module', | ||
error, | ||
); | ||
}); | ||
this.registry.on('set', (key, item) => { | ||
this.#registry.on('set', (key, item) => { | ||
Object.keys(item.proxy).forEach((name) => { | ||
const path = utils.pathnameBuilder( | ||
this.pathname, | ||
this.prefix, | ||
this.#pathname, | ||
this.#prefix, | ||
key, | ||
name, | ||
); | ||
this.log.debug( | ||
this.#log.debug( | ||
`a proxy endpoint is mounted at pathname: ${path} pointing to: ${item.proxy[name]}`, | ||
@@ -105,7 +79,14 @@ ); | ||
this.registry.on('dispose', (key) => { | ||
this.log.debug(`dispose proxy item on key "${key}"`); | ||
this.#registry.on('dispose', (key) => { | ||
this.#log.debug(`dispose proxy item on key "${key}"`); | ||
}); | ||
this.histogram = this.metrics.histogram({ | ||
this.#metrics = new Metrics(); | ||
this.#metrics.on('error', (error) => { | ||
this.#log.error( | ||
'Error emitted by metric stream in @podium/proxy module', | ||
error, | ||
); | ||
}); | ||
this.#histogram = this.#metrics.histogram({ | ||
name: 'podium_proxy_process', | ||
@@ -123,6 +104,14 @@ description: 'Measures time spent in the proxy process method', | ||
get [Symbol.toStringTag]() { | ||
return 'PodiumProxy'; | ||
get pathname() { | ||
return this.#pathname; | ||
} | ||
get prefix() { | ||
return this.#prefix; | ||
} | ||
get metrics() { | ||
return this.#metrics; | ||
} | ||
register(manifest = {}) { | ||
@@ -137,3 +126,3 @@ // Do a stringify to hande that a @podium/podlet instance is passed in. | ||
this.registry.set(obj.name, obj, Infinity); | ||
this.#registry.set(obj.name, obj, Infinity); | ||
} | ||
@@ -149,3 +138,3 @@ | ||
const endTimer = this.histogram.timer({ | ||
const endTimer = this.#histogram.timer({ | ||
labels: { | ||
@@ -157,3 +146,3 @@ name: incoming.name, | ||
return new Promise((resolve, reject) => { | ||
const match = this.pathnameParser.exec(incoming.url.pathname); | ||
const match = this.#pathnameParser.exec(incoming.url.pathname); | ||
let errored = false; | ||
@@ -165,3 +154,3 @@ | ||
for (let i = 1; i < match.length; i += 1) { | ||
const key = this.pathnameEntries[i - 1]; | ||
const key = this.#pathnameEntries[i - 1]; | ||
params[key.name] = match[i]; | ||
@@ -172,3 +161,3 @@ } | ||
// If so we might want to proxy. If not, skip rest of processing | ||
const manifest = this.registry.get(params.podiumPodletName); | ||
const manifest = this.#registry.get(params.podiumPodletName); | ||
if (!manifest) { | ||
@@ -251,3 +240,3 @@ endTimer({ labels: { podlet: params.podiumPodletName } }); | ||
this.proxy.web( | ||
this.#proxy.web( | ||
incoming.request, | ||
@@ -277,10 +266,14 @@ incoming.response, | ||
dump() { | ||
return this.registry.dump(); | ||
return this.#registry.dump(); | ||
} | ||
load(dump) { | ||
return this.registry.load(dump); | ||
return this.#registry.load(dump); | ||
} | ||
get [Symbol.toStringTag]() { | ||
return 'PodiumProxy'; | ||
} | ||
}; | ||
module.exports = PodiumProxy; |
{ | ||
"name": "@podium/proxy", | ||
"version": "5.0.0-next.3", | ||
"version": "5.0.0-next.4", | ||
"description": "Transparent http proxy. Dynamically mounts proxy targets on an existing HTTP server instance.", | ||
@@ -33,3 +33,3 @@ "license": "MIT", | ||
"lint:fix": "eslint --fix .", | ||
"test": "tap tests/*.js" | ||
"test": "tap --no-esm --no-cov --no-ts --no-jsx tests/*.js" | ||
}, | ||
@@ -54,3 +54,3 @@ "dependencies": { | ||
"@podium/test-utils": "2.2.0", | ||
"eslint": "7.3.1", | ||
"eslint": "7.5.0", | ||
"eslint-config-airbnb-base": "14.2.0", | ||
@@ -60,2 +60,3 @@ "eslint-config-prettier": "6.11.0", | ||
"eslint-plugin-prettier": "3.1.4", | ||
"babel-eslint": "10.1.0", | ||
"prettier": "2.0.5", | ||
@@ -62,0 +63,0 @@ "tap": "14.10.7" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24440
16
234