Socket
Socket
Sign inDemoInstall

http-proxy-middleware

Package Overview
Dependencies
11
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.21.0-beta.1 to 0.21.0-beta.2

dist/config-factory.d.ts

1

CHANGELOG.md

@@ -6,2 +6,3 @@ # Changelog

- feat: async router ([#379](https://github.com/chimurai/http-proxy-middleware/issues/335)) ([LiranBri](https://github.com/LiranBri))
- feat(typescript): types support ([#369](https://github.com/chimurai/http-proxy-middleware/pull/369))

@@ -8,0 +9,0 @@ ## [v0.20.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.20.0)

21

dist/config-factory.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const url = require("url");
const lodash_1 = __importDefault(require("lodash"));
const url_1 = __importDefault(require("url"));
const errors_1 = require("./errors");

@@ -17,3 +20,3 @@ const logger_1 = require("./logger");

config.context = '/';
config.options = _.assign(config.options, context);
config.options = lodash_1.default.assign(config.options, context);
// app.use('/api', proxy('http://localhost:9000'));

@@ -23,6 +26,6 @@ // app.use(proxy('http://localhost:9000/api'));

else if (isStringShortHand(context)) {
const oUrl = url.parse(context);
const oUrl = url_1.default.parse(context);
const target = [oUrl.protocol, '//', oUrl.host].join('');
config.context = oUrl.pathname || '/';
config.options = _.assign(config.options, { target }, opts);
config.options = lodash_1.default.assign(config.options, { target }, opts);
if (oUrl.protocol === 'ws:' || oUrl.protocol === 'wss:') {

@@ -35,3 +38,3 @@ config.options.ws = true;

config.context = context;
config.options = _.assign(config.options, opts);
config.options = lodash_1.default.assign(config.options, opts);
}

@@ -57,4 +60,4 @@ configureLogger(config.options);

function isStringShortHand(context) {
if (_.isString(context)) {
return !!url.parse(context).host;
if (lodash_1.default.isString(context)) {
return !!url_1.default.parse(context).host;
}

@@ -74,3 +77,3 @@ }

function isContextless(context, opts) {
return _.isPlainObject(context) && _.isEmpty(opts);
return lodash_1.default.isPlainObject(context) && lodash_1.default.isEmpty(opts);
}

@@ -77,0 +80,0 @@ function configureLogger(options) {

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const isGlob = require("is-glob");
const _ = require("lodash");
const micromatch = require("micromatch");
const url = require("url");
const is_glob_1 = __importDefault(require("is-glob"));
const lodash_1 = __importDefault(require("lodash"));
const micromatch_1 = __importDefault(require("micromatch"));
const url_1 = __importDefault(require("url"));
const errors_1 = require("./errors");

@@ -28,3 +31,3 @@ function match(context, uri, req) {

// custom matching
if (_.isFunction(context)) {
if (lodash_1.default.isFunction(context)) {
const pathname = getUrlPathName(uri);

@@ -47,3 +50,3 @@ return context(pathname, req);

const pathname = getUrlPathName(uri);
const matches = micromatch([pathname], pattern);
const matches = micromatch_1.default([pathname], pattern);
return matches && matches.length > 0;

@@ -76,9 +79,9 @@ }

function getUrlPathName(uri) {
return uri && url.parse(uri).pathname;
return uri && url_1.default.parse(uri).pathname;
}
function isStringPath(context) {
return _.isString(context) && !isGlob(context);
return lodash_1.default.isString(context) && !is_glob_1.default(context);
}
function isGlobPath(context) {
return isGlob(context);
return is_glob_1.default(context);
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const lodash_1 = __importDefault(require("lodash"));
const logger_1 = require("./logger");

@@ -29,5 +32,5 @@ const logger = logger_1.getInstance();

// and add them to the handlers object for subscription in init().
const eventName = _.camelCase('on ' + event);
const fnHandler = _.get(options, eventName);
if (_.isFunction(fnHandler)) {
const eventName = lodash_1.default.camelCase('on ' + event);
const fnHandler = lodash_1.default.get(options, eventName);
if (lodash_1.default.isFunction(fnHandler)) {
handlers[event] = fnHandler;

@@ -37,7 +40,7 @@ }

// add default error handler in absence of error handler
if (!_.isFunction(handlers.error)) {
if (!lodash_1.default.isFunction(handlers.error)) {
handlers.error = defaultErrorHandler;
}
// add default close handler in absence of close handler
if (!_.isFunction(handlers.close)) {
if (!lodash_1.default.isFunction(handlers.close)) {
handlers.close = logClose;

@@ -44,0 +47,0 @@ }

@@ -10,11 +10,21 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const httpProxy = require("http-proxy");
const _ = require("lodash");
const http_proxy_1 = __importDefault(require("http-proxy"));
const lodash_1 = __importDefault(require("lodash"));
const config_factory_1 = require("./config-factory");
const contextMatcher = require("./context-matcher");
const handlers = require("./handlers");
const contextMatcher = __importStar(require("./context-matcher"));
const handlers = __importStar(require("./handlers"));
const logger_1 = require("./logger");
const PathRewriter = require("./path-rewriter");
const Router = require("./router");
const PathRewriter = __importStar(require("./path-rewriter"));
const Router = __importStar(require("./router"));
class HttpProxyMiddleware {

@@ -79,3 +89,3 @@ constructor(context, opts) {

const originalPath = req.url;
const newProxyOptions = _.assign({}, this.proxyOptions);
const newProxyOptions = lodash_1.default.assign({}, this.proxyOptions);
// Apply in order:

@@ -126,3 +136,3 @@ // 1. option.router

// create proxy
this.proxy = httpProxy.createProxyServer({});
this.proxy = http_proxy_1.default.createProxyServer({});
this.logger.info(`[HPM] Proxy created: ${this.config.context} -> ${this.proxyOptions.target}`);

@@ -129,0 +139,0 @@ this.pathRewriter = PathRewriter.createPathRewriter(this.proxyOptions.pathRewrite); // returns undefined when "pathRewrite" is not provided

"use strict";
const http_proxy_middleware_1 = require("./http-proxy-middleware");
function proxy(context, opts) {
const { middleware } = new http_proxy_middleware_1.HttpProxyMiddleware(context, opts);
function middleware(context, options) {
const { middleware } = new http_proxy_middleware_1.HttpProxyMiddleware(context, options);
return middleware;
}
module.exports = proxy;
module.exports = middleware;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const util = require("util");
const lodash_1 = __importDefault(require("lodash"));
const util_1 = __importDefault(require("util"));
let loggerInstance;

@@ -71,3 +74,3 @@ const defaultProvider = {

const result = true;
if (fnProvider && !_.isFunction(fnProvider)) {
if (fnProvider && !lodash_1.default.isFunction(fnProvider)) {
throw new Error('[HPM] Log provider config error. Expecting a function.');

@@ -101,4 +104,4 @@ }

_interpolate() {
const fn = _.spread(util.format);
const result = fn(_.slice(arguments));
const fn = lodash_1.default.spread(util_1.default.format);
const result = fn(lodash_1.default.slice(arguments));
return result;

@@ -105,0 +108,0 @@ }

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const lodash_1 = __importDefault(require("lodash"));
const errors_1 = require("./errors");

@@ -18,3 +21,3 @@ const logger_1 = require("./logger");

}
if (_.isFunction(rewriteConfig)) {
if (lodash_1.default.isFunction(rewriteConfig)) {
const customRewriteFn = rewriteConfig;

@@ -29,3 +32,3 @@ return customRewriteFn;

let result = path;
_.forEach(rulesCache, rule => {
lodash_1.default.forEach(rulesCache, rule => {
if (rule.regex.test(path)) {

@@ -42,11 +45,11 @@ result = result.replace(rule.regex, rule.value);

function isValidRewriteConfig(rewriteConfig) {
if (_.isFunction(rewriteConfig)) {
if (lodash_1.default.isFunction(rewriteConfig)) {
return true;
}
else if (!_.isEmpty(rewriteConfig) && _.isPlainObject(rewriteConfig)) {
else if (!lodash_1.default.isEmpty(rewriteConfig) && lodash_1.default.isPlainObject(rewriteConfig)) {
return true;
}
else if (_.isUndefined(rewriteConfig) ||
_.isNull(rewriteConfig) ||
_.isEqual(rewriteConfig, {})) {
else if (lodash_1.default.isUndefined(rewriteConfig) ||
lodash_1.default.isNull(rewriteConfig) ||
lodash_1.default.isEqual(rewriteConfig, {})) {
return false;

@@ -60,4 +63,4 @@ }

const rules = [];
if (_.isPlainObject(rewriteConfig)) {
_.forIn(rewriteConfig, (value, key) => {
if (lodash_1.default.isPlainObject(rewriteConfig)) {
lodash_1.default.forIn(rewriteConfig, (value, key) => {
rules.push({

@@ -64,0 +67,0 @@ regex: new RegExp(key),

@@ -10,4 +10,7 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const lodash_1 = __importDefault(require("lodash"));
const logger_1 = require("./logger");

@@ -19,6 +22,6 @@ const logger = logger_1.getInstance();

const router = config.router;
if (_.isPlainObject(router)) {
if (lodash_1.default.isPlainObject(router)) {
newTarget = getTargetFromProxyTable(req, router);
}
else if (_.isFunction(router)) {
else if (lodash_1.default.isFunction(router)) {
newTarget = yield router(req);

@@ -35,3 +38,3 @@ }

const hostAndPath = host + path;
_.forIn(table, (value, key) => {
lodash_1.default.forIn(table, (value, key) => {
if (containsPath(key)) {

@@ -38,0 +41,0 @@ if (hostAndPath.indexOf(key) > -1) {

{
"name": "http-proxy-middleware",
"version": "0.21.0-beta.1",
"version": "0.21.0-beta.2",
"description": "The one-liner node.js proxy middleware for connect, express and browser-sync",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [

@@ -54,3 +55,2 @@ "dist"

"@types/express": "^4.17.0",
"@types/http-proxy": "^1.17.0",
"@types/is-glob": "^4.0.0",

@@ -76,2 +76,3 @@ "@types/jest": "^24.0.15",

"dependencies": {
"@types/http-proxy": "^1.17.0",
"http-proxy": "^1.17.0",

@@ -78,0 +79,0 @@ "is-glob": "^4.0.1",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc