@podium/proxy
Advanced tools
Comparing version 3.0.0-beta.3 to 3.0.0-beta.4
@@ -14,4 +14,2 @@ 'use strict'; | ||
const State = require('./state'); | ||
/* | ||
@@ -149,17 +147,9 @@ const HTTP_AGENT = new http.Agent({ | ||
process(req, res) { | ||
// TODO: replace with a instance check when there is one PodiumState | ||
// class used by multiple modules. | ||
let state; | ||
if (Object.prototype.toString.call(req) === '[object PodiumState]') { | ||
state = req; | ||
} else { | ||
state = new State(req, res); | ||
// TODO: Only needed to support 2.x version of Layout. | ||
// Remove when layout is http framework free. | ||
state.context = utils.getFromLocalsPodium(res, 'context'); | ||
process(incoming) { | ||
if (Object.prototype.toString.call(incoming) !== '[object PodiumHttpIncoming]') { | ||
throw TypeError('Argument must be of type "PodiumHttpIncoming"'); | ||
} | ||
return new Promise((resolve, reject) => { | ||
const match = this.pathnameParser.exec(state.url.pathname); | ||
const match = this.pathnameParser.exec(incoming.url.pathname); | ||
@@ -178,3 +168,3 @@ if (match) { | ||
if (!manifest) { | ||
resolve(state); | ||
resolve(incoming); | ||
return; | ||
@@ -187,3 +177,3 @@ } | ||
if (!target) { | ||
resolve(state); | ||
resolve(incoming); | ||
return; | ||
@@ -200,5 +190,5 @@ } | ||
target, | ||
`${state.url.protocol}//${state.url.hostname}${ | ||
state.url.port ? ':' : '' | ||
}${state.url.port}`, | ||
`${incoming.url.protocol}//${incoming.url.hostname}${ | ||
incoming.url.port ? ':' : '' | ||
}${incoming.url.port}`, | ||
); | ||
@@ -215,4 +205,4 @@ } | ||
// target pathname | ||
if (state.url.search) { | ||
target += `${state.url.search}`; | ||
if (incoming.url.search) { | ||
target += `${incoming.url.search}`; | ||
} | ||
@@ -222,4 +212,4 @@ | ||
utils.serializeContext( | ||
state.request.headers, | ||
state.context, | ||
incoming.request.headers, | ||
incoming.context, | ||
params.podiumPodletName, | ||
@@ -241,7 +231,7 @@ ); | ||
state.response.on('finish', () => { | ||
incoming.response.on('finish', () => { | ||
resolve(); | ||
}); | ||
this.proxy.web(state.request, state.response, config, error => { | ||
this.proxy.web(incoming.request, incoming.response, config, error => { | ||
reject(error); | ||
@@ -252,20 +242,6 @@ }); | ||
} | ||
resolve(state); | ||
resolve(incoming); | ||
}); | ||
} | ||
middleware() { | ||
return (req, res, next) => { | ||
this.process(req, res) | ||
.then(state => { | ||
if (state) { | ||
next(); | ||
} | ||
}) | ||
.catch(error => { | ||
next(error); | ||
}); | ||
}; | ||
} | ||
dump() { | ||
@@ -272,0 +248,0 @@ return this.registry.dump(); |
{ | ||
"name": "@podium/proxy", | ||
"version": "3.0.0-beta.3", | ||
"version": "3.0.0-beta.4", | ||
"description": "Transparent http proxy. Dynamically mounts proxy targets on an existing HTTP server instance.", | ||
@@ -35,7 +35,6 @@ "license": "MIT", | ||
"@podium/schemas": "3.0.0", | ||
"@podium/utils": "3.0.0", | ||
"@podium/utils": "3.1.0", | ||
"abslog": "2.2.3", | ||
"http-proxy": "1.17.0", | ||
"joi": "14.3.1", | ||
"original-url": "1.2.2", | ||
"path-to-regexp": "3.0.0", | ||
@@ -42,0 +41,0 @@ "ttl-mem-cache": "4.0.2" |
8
17523
4
211
+ Added@podium/utils@3.1.0(transitive)
+ Addedoriginal-url@1.2.3(transitive)
- Removedoriginal-url@1.2.2
- Removed@podium/utils@3.0.0(transitive)
- Removedoriginal-url@1.2.2(transitive)
Updated@podium/utils@3.1.0