http-proxy-middleware 0.21.0-beta.3 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/logger.js CHANGED
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const lodash_1 = __importDefault(require("lodash"));
7
- const util_1 = __importDefault(require("util"));
3
+ const _ = require("lodash");
4
+ const util = require("util");
8
5
  let loggerInstance;
9
6
  const defaultProvider = {
10
7
  // tslint:disable: no-console
@@ -71,7 +68,7 @@ class Logger {
71
68
  }
72
69
  isValidProvider(fnProvider) {
73
70
  const result = true;
74
- if (fnProvider && !lodash_1.default.isFunction(fnProvider)) {
71
+ if (fnProvider && !_.isFunction(fnProvider)) {
75
72
  throw new Error('[HPM] Log provider config error. Expecting a function.');
76
73
  }
77
74
  return result;
@@ -100,8 +97,8 @@ class Logger {
100
97
  // make sure logged messages and its data are return interpolated
101
98
  // make it possible for additional log data, such date/time or custom prefix.
102
99
  _interpolate() {
103
- const fn = lodash_1.default.spread(util_1.default.format);
104
- const result = fn(lodash_1.default.slice(arguments));
100
+ const fn = _.spread(util.format);
101
+ const result = fn(_.slice(arguments));
105
102
  return result;
106
103
  }
107
104
  }
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const lodash_1 = __importDefault(require("lodash"));
3
+ const _ = require("lodash");
7
4
  const errors_1 = require("./errors");
8
5
  const logger_1 = require("./logger");
9
6
  const logger = logger_1.getInstance();
@@ -18,7 +15,7 @@ function createPathRewriter(rewriteConfig) {
18
15
  if (!isValidRewriteConfig(rewriteConfig)) {
19
16
  return;
20
17
  }
21
- if (lodash_1.default.isFunction(rewriteConfig)) {
18
+ if (_.isFunction(rewriteConfig)) {
22
19
  const customRewriteFn = rewriteConfig;
23
20
  return customRewriteFn;
24
21
  }
@@ -28,7 +25,7 @@ function createPathRewriter(rewriteConfig) {
28
25
  }
29
26
  function rewritePath(path) {
30
27
  let result = path;
31
- lodash_1.default.forEach(rulesCache, rule => {
28
+ _.forEach(rulesCache, rule => {
32
29
  if (rule.regex.test(path)) {
33
30
  result = result.replace(rule.regex, rule.value);
34
31
  logger.debug('[HPM] Rewriting path from "%s" to "%s"', path, result);
@@ -40,15 +37,15 @@ function createPathRewriter(rewriteConfig) {
40
37
  }
41
38
  exports.createPathRewriter = createPathRewriter;
42
39
  function isValidRewriteConfig(rewriteConfig) {
43
- if (lodash_1.default.isFunction(rewriteConfig)) {
40
+ if (_.isFunction(rewriteConfig)) {
44
41
  return true;
45
42
  }
46
- else if (!lodash_1.default.isEmpty(rewriteConfig) && lodash_1.default.isPlainObject(rewriteConfig)) {
43
+ else if (!_.isEmpty(rewriteConfig) && _.isPlainObject(rewriteConfig)) {
47
44
  return true;
48
45
  }
49
- else if (lodash_1.default.isUndefined(rewriteConfig) ||
50
- lodash_1.default.isNull(rewriteConfig) ||
51
- lodash_1.default.isEqual(rewriteConfig, {})) {
46
+ else if (_.isUndefined(rewriteConfig) ||
47
+ _.isNull(rewriteConfig) ||
48
+ _.isEqual(rewriteConfig, {})) {
52
49
  return false;
53
50
  }
54
51
  else {
@@ -57,8 +54,8 @@ function isValidRewriteConfig(rewriteConfig) {
57
54
  }
58
55
  function parsePathRewriteRules(rewriteConfig) {
59
56
  const rules = [];
60
- if (lodash_1.default.isPlainObject(rewriteConfig)) {
61
- lodash_1.default.forIn(rewriteConfig, (value, key) => {
57
+ if (_.isPlainObject(rewriteConfig)) {
58
+ _.forIn(rewriteConfig, (value, key) => {
62
59
  rules.push({
63
60
  regex: new RegExp(key),
64
61
  value: rewriteConfig[key]
package/dist/router.js CHANGED
@@ -8,21 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const lodash_1 = __importDefault(require("lodash"));
12
+ const _ = require("lodash");
16
13
  const logger_1 = require("./logger");
17
14
  const logger = logger_1.getInstance();
18
15
  function getTarget(req, config) {
19
16
  return __awaiter(this, void 0, void 0, function* () {
20
17
  let newTarget;
21
18
  const router = config.router;
22
- if (lodash_1.default.isPlainObject(router)) {
19
+ if (_.isPlainObject(router)) {
23
20
  newTarget = getTargetFromProxyTable(req, router);
24
21
  }
25
- else if (lodash_1.default.isFunction(router)) {
22
+ else if (_.isFunction(router)) {
26
23
  newTarget = yield router(req);
27
24
  }
28
25
  return newTarget;
@@ -34,7 +31,7 @@ function getTargetFromProxyTable(req, table) {
34
31
  const host = req.headers.host;
35
32
  const path = req.url;
36
33
  const hostAndPath = host + path;
37
- lodash_1.default.forIn(table, (value, key) => {
34
+ _.forIn(table, (value, key) => {
38
35
  if (containsPath(key)) {
39
36
  if (hostAndPath.indexOf(key) > -1) {
40
37
  // match 'localhost:3000/api'