http-proxy-middleware 2.0.1 → 2.0.2

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/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/chimurai/http-proxy-middleware/CI/master?style=flat-square)](https://github.com/chimurai/http-proxy-middleware/actions?query=branch%3Amaster)
4
4
  [![Coveralls](https://img.shields.io/coveralls/chimurai/http-proxy-middleware.svg?style=flat-square)](https://coveralls.io/r/chimurai/http-proxy-middleware)
5
- [![dependency Status](https://img.shields.io/david/chimurai/http-proxy-middleware.svg?style=flat-square)](https://david-dm.org/chimurai/http-proxy-middleware#info=dependencies)
6
5
  [![dependency Status](https://snyk.io/test/npm/http-proxy-middleware/badge.svg?style=flat-square)](https://snyk.io/test/npm/http-proxy-middleware)
7
6
  [![npm](https://img.shields.io/npm/v/http-proxy-middleware?color=%23CC3534&style=flat-square)](https://www.npmjs.com/package/http-proxy-middleware)
8
7
 
@@ -128,6 +127,7 @@ const express = require('express');
128
127
  const { createProxyMiddleware } = require('http-proxy-middleware');
129
128
 
130
129
  // proxy middleware options
130
+ /** @type {import('http-proxy-middleware/dist/types').Options} */
131
131
  const options = {
132
132
  target: 'http://www.example.org', // target host
133
133
  changeOrigin: true, // needed for virtual hosted sites
@@ -341,7 +341,7 @@ Subscribe to [http-proxy events](https://github.com/nodejitsu/node-http-proxy#li
341
341
  ```javascript
342
342
  function onOpen(proxySocket) {
343
343
  // listen for messages coming FROM the target here
344
- proxySocket.on('data', hybiParseAndLogMessage);
344
+ proxySocket.on('data', hybridParseAndLogMessage);
345
345
  }
346
346
  ```
347
347
 
@@ -586,6 +586,9 @@ $ yarn test
586
586
 
587
587
  # code coverage
588
588
  $ yarn cover
589
+
590
+ # check spelling mistakes
591
+ $ yarn spellcheck
589
592
  ```
590
593
 
591
594
  ## Changelog
@@ -596,4 +599,4 @@ $ yarn cover
596
599
 
597
600
  The MIT License (MIT)
598
601
 
599
- Copyright (c) 2015-2021 Steven Chim
602
+ Copyright (c) 2015-2022 Steven Chim
package/dist/_handlers.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getHandlers = exports.init = void 0;
4
4
  const logger_1 = require("./logger");
5
- const logger = logger_1.getInstance();
5
+ const logger = (0, logger_1.getInstance)();
6
6
  function init(proxy, option) {
7
7
  const handlers = getHandlers(option);
8
8
  for (const eventName of Object.keys(handlers)) {
@@ -66,7 +66,7 @@ function defaultErrorHandler(err, req, res) {
66
66
  }
67
67
  }
68
68
  }
69
- res.end(`Error occured while trying to proxy: ${host}${req.url}`);
69
+ res.end(`Error occurred while trying to proxy: ${host}${req.url}`);
70
70
  }
71
71
  function logClose(req, socket, head) {
72
72
  // view disconnected websocket connections
@@ -5,7 +5,7 @@ const isPlainObj = require("is-plain-obj");
5
5
  const url = require("url");
6
6
  const errors_1 = require("./errors");
7
7
  const logger_1 = require("./logger");
8
- const logger = logger_1.getInstance();
8
+ const logger = (0, logger_1.getInstance)();
9
9
  function createConfig(context, opts) {
10
10
  // structure of config object to be returned
11
11
  const config = {
@@ -7,7 +7,7 @@ const querystring = require("querystring");
7
7
  */
8
8
  function fixRequestBody(proxyReq, req) {
9
9
  const requestBody = req.body;
10
- if (!requestBody || !Object.keys(requestBody).length) {
10
+ if (!requestBody) {
11
11
  return;
12
12
  }
13
13
  const contentType = proxyReq.getHeader('Content-Type');
@@ -10,7 +10,7 @@ const PathRewriter = require("./path-rewriter");
10
10
  const Router = require("./router");
11
11
  class HttpProxyMiddleware {
12
12
  constructor(context, opts) {
13
- this.logger = logger_1.getInstance();
13
+ this.logger = (0, logger_1.getInstance)();
14
14
  this.wsInternalSubscribed = false;
15
15
  this.serverOnCloseSubscribed = false;
16
16
  // https://github.com/Microsoft/TypeScript/wiki/'this'-in-TypeScript#red-flags-for-this
@@ -98,7 +98,7 @@ class HttpProxyMiddleware {
98
98
  await this.applyPathRewrite(req, this.pathRewriter);
99
99
  // debug logging for both http(s) and websockets
100
100
  if (this.proxyOptions.logLevel === 'debug') {
101
- const arrow = logger_1.getArrow(originalPath, req.url, this.proxyOptions.target, newProxyOptions.target);
101
+ const arrow = (0, logger_1.getArrow)(originalPath, req.url, this.proxyOptions.target, newProxyOptions.target);
102
102
  this.logger.debug('[HPM] %s %s %s %s', req.method, originalPath, arrow, newProxyOptions.target);
103
103
  }
104
104
  return newProxyOptions;
@@ -135,7 +135,7 @@ class HttpProxyMiddleware {
135
135
  const errReference = 'https://nodejs.org/api/errors.html#errors_common_system_errors'; // link to Node Common Systems Errors page
136
136
  this.logger.error(errorMessage, requestHref, targetHref, err.code || err, errReference);
137
137
  };
138
- this.config = config_factory_1.createConfig(context, opts);
138
+ this.config = (0, config_factory_1.createConfig)(context, opts);
139
139
  this.proxyOptions = this.config.options;
140
140
  // create proxy
141
141
  this.proxy = httpProxy.createProxyServer({});
@@ -4,7 +4,7 @@ exports.createPathRewriter = void 0;
4
4
  const isPlainObj = require("is-plain-obj");
5
5
  const errors_1 = require("./errors");
6
6
  const logger_1 = require("./logger");
7
- const logger = logger_1.getInstance();
7
+ const logger = (0, logger_1.getInstance)();
8
8
  /**
9
9
  * Create rewrite function, to cache parsed rewrite rules.
10
10
  *
package/dist/router.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getTarget = void 0;
4
4
  const isPlainObj = require("is-plain-obj");
5
5
  const logger_1 = require("./logger");
6
- const logger = logger_1.getInstance();
6
+ const logger = (0, logger_1.getInstance)();
7
7
  async function getTarget(req, config) {
8
8
  let newTarget;
9
9
  const router = config.router;
package/dist/types.d.ts CHANGED
@@ -45,10 +45,10 @@ export declare type LogProviderCallback = (provider: LogProvider) => LogProvider
45
45
  * Use types based on the events listeners from http-proxy
46
46
  * https://github.com/DefinitelyTyped/DefinitelyTyped/blob/51504fd999031b7f025220fab279f1b2155cbaff/types/http-proxy/index.d.ts
47
47
  */
48
- export declare type OnErrorCallback = (err: Error, req: http.IncomingMessage, res: http.ServerResponse, target?: string | Partial<url.Url>) => void;
49
- export declare type OnProxyResCallback = (proxyRes: http.IncomingMessage, req: http.IncomingMessage, res: http.ServerResponse) => void;
50
- export declare type OnProxyReqCallback = (proxyReq: http.ClientRequest, req: http.IncomingMessage, res: http.ServerResponse, options: httpProxy.ServerOptions) => void;
51
- export declare type OnProxyReqWsCallback = (proxyReq: http.ClientRequest, req: http.IncomingMessage, socket: net.Socket, options: httpProxy.ServerOptions, head: any) => void;
52
- export declare type OnCloseCallback = (proxyRes: http.IncomingMessage, proxySocket: net.Socket, proxyHead: any) => void;
48
+ export declare type OnErrorCallback = (err: Error, req: Request, res: Response, target?: string | Partial<url.Url>) => void;
49
+ export declare type OnProxyResCallback = (proxyRes: http.IncomingMessage, req: Request, res: Response) => void;
50
+ export declare type OnProxyReqCallback = (proxyReq: http.ClientRequest, req: Request, res: Response, options: httpProxy.ServerOptions) => void;
51
+ export declare type OnProxyReqWsCallback = (proxyReq: http.ClientRequest, req: Request, socket: net.Socket, options: httpProxy.ServerOptions, head: any) => void;
52
+ export declare type OnCloseCallback = (proxyRes: Response, proxySocket: net.Socket, proxyHead: any) => void;
53
53
  export declare type OnOpenCallback = (proxySocket: net.Socket) => void;
54
54
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "http-proxy-middleware",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "The one-liner node.js proxy middleware for connect, express and browser-sync",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,7 +21,9 @@
21
21
  "test": "jest",
22
22
  "precoverage": "yarn build",
23
23
  "coverage": "jest --coverage --coverageReporters=lcov",
24
- "prepare": "husky install && yarn build && rm dist/tsconfig.tsbuildinfo"
24
+ "prepare": "husky install",
25
+ "prepack": "yarn build && rm dist/tsconfig.tsbuildinfo",
26
+ "spellcheck": "npx --yes cspell --show-context --show-suggestions '**/*.*'"
25
27
  },
26
28
  "repository": {
27
29
  "type": "git",
@@ -51,43 +53,46 @@
51
53
  },
52
54
  "homepage": "https://github.com/chimurai/http-proxy-middleware#readme",
53
55
  "devDependencies": {
54
- "@commitlint/cli": "^12.1.4",
55
- "@commitlint/config-conventional": "^12.1.4",
56
- "@types/express": "4.17.7",
57
- "@types/is-glob": "^4.0.1",
58
- "@types/jest": "^26.0.23",
59
- "@types/micromatch": "^4.0.1",
60
- "@types/node": "^15.6.2",
61
- "@types/supertest": "^2.0.11",
62
- "@types/ws": "^7.4.4",
63
- "@typescript-eslint/eslint-plugin": "^4.26.0",
64
- "@typescript-eslint/parser": "^4.26.0",
65
- "body-parser": "^1.19.0",
66
- "browser-sync": "^2.26.14",
67
- "connect": "^3.7.0",
68
- "eslint": "^7.27.0",
69
- "eslint-config-prettier": "^8.3.0",
70
- "eslint-plugin-prettier": "^3.4.0",
71
- "express": "^4.17.1",
72
- "get-port": "^5.1.1",
73
- "husky": "^6.0.0",
74
- "jest": "^27.0.3",
75
- "lint-staged": "^11.0.0",
76
- "mockttp": "^1.2.2",
77
- "open": "^8.2.0",
78
- "prettier": "^2.3.0",
79
- "supertest": "^6.1.3",
80
- "ts-jest": "^27.0.2",
81
- "typescript": "^4.3.2",
82
- "ws": "^7.4.6"
56
+ "@commitlint/cli": "16.1.0",
57
+ "@commitlint/config-conventional": "16.0.0",
58
+ "@types/express": "4.17.13",
59
+ "@types/is-glob": "4.0.2",
60
+ "@types/jest": "27.4.0",
61
+ "@types/micromatch": "4.0.2",
62
+ "@types/node": "17.0.10",
63
+ "@types/supertest": "2.0.11",
64
+ "@types/ws": "8.2.2",
65
+ "@typescript-eslint/eslint-plugin": "5.10.0",
66
+ "@typescript-eslint/parser": "5.10.0",
67
+ "body-parser": "1.19.1",
68
+ "browser-sync": "2.27.7",
69
+ "connect": "3.7.0",
70
+ "eslint": "8.7.0",
71
+ "eslint-config-prettier": "8.3.0",
72
+ "eslint-plugin-prettier": "4.0.0",
73
+ "express": "4.17.2",
74
+ "get-port": "5.1.1",
75
+ "husky": "7.0.4",
76
+ "jest": "27.4.7",
77
+ "lint-staged": "12.2.2",
78
+ "mockttp": "2.5.1",
79
+ "open": "8.4.0",
80
+ "prettier": "2.5.1",
81
+ "supertest": "6.2.2",
82
+ "ts-jest": "27.1.3",
83
+ "typescript": "4.5.5",
84
+ "ws": "8.4.2"
83
85
  },
84
86
  "dependencies": {
85
- "@types/http-proxy": "^1.17.5",
87
+ "@types/http-proxy": "^1.17.8",
86
88
  "http-proxy": "^1.18.1",
87
89
  "is-glob": "^4.0.1",
88
90
  "is-plain-obj": "^3.0.0",
89
91
  "micromatch": "^4.0.2"
90
92
  },
93
+ "peerDependencies": {
94
+ "@types/express": "^4.17.13"
95
+ },
91
96
  "engines": {
92
97
  "node": ">=12.0.0"
93
98
  },