proxy rewrites: fixed a case where errors were thrown if the resolved 'to' address contained params (e.g. '*', ':param' etc)

This commit is contained in:
Lloyd Brookes
2016-05-04 14:41:23 +01:00
parent 5f75b46173
commit 8f67b815f5
2 changed files with 1 additions and 8 deletions

View File

@ -88,6 +88,7 @@ function localWebServer (options) {
if (options.rewrite && options.rewrite.length) {
options.rewrite.forEach(route => {
if (route.to) {
/* `to` address is remote if the url specifies a host */
if (url.parse(route.to).host) {
debug('proxy rewrite', `${route.from} -> ${route.to}`)
app.use(_.all(route.from, mw.proxyRequest(route, app)))

View File

@ -33,14 +33,6 @@ function proxyRequest (route, app) {
.replace(re, arguments[index + 1] || '')
})
/* test no keys remain in the new path */
keys.length = 0
pathToRegexp(url.parse(route.new).path, keys)
if (keys.length) {
this.throw(500, `[PROXY] Invalid target URL: ${route.new}`)
return next()
}
this.response = false
debug('proxy request', `from: ${this.path}, to: ${url.parse(route.new).href}`)