Browse Source

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

master
Lloyd Brookes 9 years ago
parent
commit
8f67b815f5
  1. 1
      lib/local-web-server.js
  2. 8
      lib/middleware.js

1
lib/local-web-server.js

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

8
lib/middleware.js

@ -33,14 +33,6 @@ function proxyRequest (route, app) {
.replace(re, arguments[index + 1] || '') .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 this.response = false
debug('proxy request', `from: ${this.path}, to: ${url.parse(route.new).href}`) debug('proxy request', `from: ${this.path}, to: ${url.parse(route.new).href}`)

Loading…
Cancel
Save