http-proxy-middleware
Advanced tools
Comparing version 0.20.0 to 0.21.0-beta.1
# Changelog | ||
## next | ||
- feat: async router ([#379](https://github.com/chimurai/http-proxy-middleware/issues/335)) ([LiranBri](https://github.com/LiranBri)) | ||
## [v0.20.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.20.0) | ||
@@ -4,0 +8,0 @@ |
@@ -26,3 +26,3 @@ "use strict"; | ||
if (this.shouldProxy(this.config.context, req)) { | ||
const activeProxyOptions = this.prepareProxyRequest(req); | ||
const activeProxyOptions = yield this.prepareProxyRequest(req); | ||
this.proxy.web(req, res, activeProxyOptions); | ||
@@ -46,9 +46,9 @@ } | ||
}; | ||
this.handleUpgrade = (req, socket, head) => { | ||
this.handleUpgrade = (req, socket, head) => __awaiter(this, void 0, void 0, function* () { | ||
if (this.shouldProxy(this.config.context, req)) { | ||
const activeProxyOptions = this.prepareProxyRequest(req); | ||
const activeProxyOptions = yield this.prepareProxyRequest(req); | ||
this.proxy.ws(req, socket, head, activeProxyOptions); | ||
this.logger.info('[HPM] Upgrading to WebSocket'); | ||
} | ||
}; | ||
}); | ||
/** | ||
@@ -74,3 +74,3 @@ * Determine whether request should be proxied. | ||
*/ | ||
this.prepareProxyRequest = req => { | ||
this.prepareProxyRequest = (req) => __awaiter(this, void 0, void 0, function* () { | ||
// https://github.com/chimurai/http-proxy-middleware/issues/17 | ||
@@ -85,3 +85,3 @@ // https://github.com/chimurai/http-proxy-middleware/issues/94 | ||
// 2. option.pathRewrite | ||
this.applyRouter(req, newProxyOptions); | ||
yield this.applyRouter(req, newProxyOptions); | ||
this.applyPathRewrite(req, this.pathRewriter); | ||
@@ -94,8 +94,8 @@ // debug logging for both http(s) and websockets | ||
return newProxyOptions; | ||
}; | ||
}); | ||
// Modify option.target when router present. | ||
this.applyRouter = (req, options) => { | ||
this.applyRouter = (req, options) => __awaiter(this, void 0, void 0, function* () { | ||
let newTarget; | ||
if (options.router) { | ||
newTarget = Router.getTarget(req, options); | ||
newTarget = yield Router.getTarget(req, options); | ||
if (newTarget) { | ||
@@ -106,3 +106,3 @@ this.logger.debug('[HPM] Router new target: %s -> "%s"', options.target, newTarget); | ||
} | ||
}; | ||
}); | ||
// rewrite path | ||
@@ -109,0 +109,0 @@ this.applyPathRewrite = (req, pathRewriter) => { |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -7,11 +15,13 @@ const _ = require("lodash"); | ||
function getTarget(req, config) { | ||
let newTarget; | ||
const router = config.router; | ||
if (_.isPlainObject(router)) { | ||
newTarget = getTargetFromProxyTable(req, router); | ||
} | ||
else if (_.isFunction(router)) { | ||
newTarget = router(req); | ||
} | ||
return newTarget; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let newTarget; | ||
const router = config.router; | ||
if (_.isPlainObject(router)) { | ||
newTarget = getTargetFromProxyTable(req, router); | ||
} | ||
else if (_.isFunction(router)) { | ||
newTarget = yield router(req); | ||
} | ||
return newTarget; | ||
}); | ||
} | ||
@@ -18,0 +28,0 @@ exports.getTarget = getTarget; |
{ | ||
"name": "http-proxy-middleware", | ||
"version": "0.20.0", | ||
"version": "0.21.0-beta.1", | ||
"description": "The one-liner node.js proxy middleware for connect, express and browser-sync", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -220,2 +220,8 @@ # http-proxy-middleware | ||
} | ||
// Asynchronous router function which returns promise | ||
router: async function(req) { | ||
const url = await doSomeIO(); | ||
return url; | ||
} | ||
``` | ||
@@ -222,0 +228,0 @@ |
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
52422
643
505