@podium/proxy
Advanced tools
Comparing version 5.0.0-next.6 to 5.0.0-next.7
@@ -0,1 +1,8 @@ | ||
# [5.0.0-next.7](https://github.com/podium-lib/proxy/compare/v5.0.0-next.6...v5.0.0-next.7) (2022-09-21) | ||
### Features | ||
* Support manifest with array of proxy endpoints ([#226](https://github.com/podium-lib/proxy/issues/226)) ([330384b](https://github.com/podium-lib/proxy/commit/330384bb5179bc21c9a4d2518fa349e801855880)) | ||
# [5.0.0-next.6](https://github.com/podium-lib/proxy/compare/v5.0.0-next.5...v5.0.0-next.6) (2022-05-09) | ||
@@ -2,0 +9,0 @@ |
@@ -7,3 +7,2 @@ import { pathToRegexp } from 'path-to-regexp'; | ||
import * as utils from '@podium/utils'; | ||
import Cache from 'ttl-mem-cache'; | ||
import Proxy from 'http-proxy'; | ||
@@ -25,3 +24,2 @@ | ||
timeout = 20000, | ||
maxAge = Infinity, | ||
logger = null, | ||
@@ -53,29 +51,4 @@ } = {}) { | ||
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) => { | ||
Object.keys(item.proxy).forEach((name) => { | ||
const path = utils.pathnameBuilder( | ||
this.#pathname, | ||
this.#prefix, | ||
key, | ||
name, | ||
); | ||
this.#log.debug( | ||
`a proxy endpoint is mounted at pathname: ${path} pointing to: ${item.proxy[name]}`, | ||
); | ||
}); | ||
}); | ||
this.#registry = new Map(); | ||
this.#registry.on('dispose', (key) => { | ||
this.#log.debug(`dispose proxy item on key "${key}"`); | ||
}); | ||
this.#metrics = new Metrics(); | ||
@@ -126,3 +99,33 @@ this.#metrics.on('error', (error) => { | ||
this.#registry.set(obj.name, obj, Infinity); | ||
if (Array.isArray(obj.proxy)) { | ||
obj.proxy.forEach((item) => { | ||
this.#registry.set(`${obj.name}/${item.name}`, item.target); | ||
const path = utils.pathnameBuilder( | ||
this.#pathname, | ||
this.#prefix, | ||
obj.name, | ||
item.name, | ||
); | ||
this.#log.debug( | ||
`a proxy endpoint is mounted at pathname: ${path} pointing to: ${item.target}`, | ||
); | ||
}); | ||
} else { | ||
// NOTE: This can be removed when the object notation is removed from the schema | ||
// and the manifest only support an array for the proxy property. | ||
Object.keys(obj.proxy).forEach((key) => { | ||
this.#registry.set(`${obj.name}/${key}`, obj.proxy[key]); | ||
const path = utils.pathnameBuilder( | ||
this.#pathname, | ||
this.#prefix, | ||
obj.name, | ||
key, | ||
); | ||
this.#log.debug( | ||
`a proxy endpoint is mounted at pathname: ${path} pointing to: ${obj.proxy[key]}`, | ||
); | ||
}); | ||
} | ||
} | ||
@@ -162,15 +165,7 @@ | ||
// See if "podiumPodletName" matches a podlet in registry. | ||
// If so we might want to proxy. If not, skip rest of processing | ||
const manifest = this.#registry.get(params.podiumPodletName); | ||
if (!manifest) { | ||
endTimer({ labels: { podlet: params.podiumPodletName } }); | ||
resolve(incoming); | ||
return; | ||
} | ||
const key = `${params.podiumPodletName}/${params.podiumProxyName}`; | ||
// See if podlet has a matching proxy entry. | ||
// If so we want to proxy. If not, skip rest of processing | ||
let target = manifest.proxy[params.podiumProxyName]; | ||
if (!target) { | ||
if (!this.#registry.has(key)) { | ||
endTimer({ labels: { podlet: params.podiumPodletName } }); | ||
@@ -181,2 +176,4 @@ resolve(incoming); | ||
let target = this.#registry.get(key); | ||
// See if proxy entry is relative or not. | ||
@@ -268,10 +265,2 @@ // In a layout server it will never be relative since the | ||
dump() { | ||
return this.#registry.dump(); | ||
} | ||
load(dump) { | ||
return this.#registry.load(dump); | ||
} | ||
get [Symbol.toStringTag]() { | ||
@@ -278,0 +267,0 @@ return 'PodiumProxy'; |
{ | ||
"name": "@podium/proxy", | ||
"version": "5.0.0-next.6", | ||
"version": "5.0.0-next.7", | ||
"description": "Transparent http proxy. Dynamically mounts proxy targets on an existing HTTP server instance.", | ||
@@ -39,8 +39,7 @@ "type": "module", | ||
"@metrics/client": "2.5.0", | ||
"@podium/schemas": "5.0.0-next.4", | ||
"@podium/schemas": "5.0.0-next.6", | ||
"@podium/utils": "5.0.0-next.6", | ||
"abslog": "2.4.0", | ||
"http-proxy": "1.18.1", | ||
"path-to-regexp": "6.2.1", | ||
"ttl-mem-cache": "4.1.0" | ||
"path-to-regexp": "6.2.1" | ||
}, | ||
@@ -47,0 +46,0 @@ "devDependencies": { |
55626
6
229
+ Added@podium/schemas@5.0.0-next.6(transitive)
+ Addedajv@8.11.0(transitive)
+ Addedajv-formats@2.1.1(transitive)
- Removedttl-mem-cache@4.1.0
- Removed@podium/schemas@5.0.0-next.4(transitive)
- Removedajv@8.1.0(transitive)
- Removedajv-formats@2.0.2(transitive)
- Removedttl-mem-cache@4.1.0(transitive)
Updated@podium/schemas@5.0.0-next.6