http-proxy-middleware 2.0.1 → 2.0.4

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
 
@@ -10,14 +9,14 @@ Node.js proxying made simple. Configure proxy middleware with ease for [connect]
10
9
 
11
10
  Powered by the popular Nodejitsu [`http-proxy`](https://github.com/nodejitsu/node-http-proxy). [![GitHub stars](https://img.shields.io/github/stars/nodejitsu/node-http-proxy.svg?style=social&label=Star)](https://github.com/nodejitsu/node-http-proxy)
12
11
 
13
- ## ⚠️ Note
12
+ ## ⚠️ Note <!-- omit in toc -->
14
13
 
15
- This page is showing documentation for version v1.x.x ([release notes](https://github.com/chimurai/http-proxy-middleware/releases))
14
+ This page is showing documentation for version v2.x.x ([release notes](https://github.com/chimurai/http-proxy-middleware/releases))
16
15
 
17
16
  If you're looking for v0.x documentation. Go to:
18
17
  https://github.com/chimurai/http-proxy-middleware/tree/v0.21.0#readme
19
18
 
20
- ## TL;DR
19
+ ## TL;DR <!-- omit in toc -->
21
20
 
22
21
  Proxy `/api` requests to `http://www.example.org`
23
22
 
@@ -53,9 +52,7 @@ _All_ `http-proxy` [options](https://github.com/nodejitsu/node-http-proxy#option
53
52
 
54
53
  :bulb: **Tip:** Set the option `changeOrigin` to `true` for [name-based virtual hosted sites](http://en.wikipedia.org/wiki/Virtual_hosting#Name-based).
55
54
 
56
- ## Table of Contents
57
-
58
- <!-- MarkdownTOC autolink=true bracket=round depth=2 -->
55
+ ## Table of Contents <!-- omit in toc -->
59
56
 
60
57
  - [Install](#install)
61
58
  - [Core concept](#core-concept)
@@ -66,7 +63,7 @@ _All_ `http-proxy` [options](https://github.com/nodejitsu/node-http-proxy#option
66
63
  - [http-proxy events](#http-proxy-events)
67
64
  - [http-proxy options](#http-proxy-options)
68
65
  - [Shorthand](#shorthand)
69
- - [app.use\(path, proxy\)](#appusepath-proxy)
66
+ - [app.use(path, proxy)](#appusepath-proxy)
70
67
  - [WebSocket](#websocket)
71
68
  - [External WebSocket upgrade](#external-websocket-upgrade)
72
69
  - [Intercept and manipulate requests](#intercept-and-manipulate-requests)
@@ -78,8 +75,6 @@ _All_ `http-proxy` [options](https://github.com/nodejitsu/node-http-proxy#option
78
75
  - [Changelog](#changelog)
79
76
  - [License](#license)
80
77
 
81
- <!-- /MarkdownTOC -->
82
-
83
78
  ## Install
84
79
 
85
80
  ```bash
@@ -128,6 +123,7 @@ const express = require('express');
128
123
  const { createProxyMiddleware } = require('http-proxy-middleware');
129
124
 
130
125
  // proxy middleware options
126
+ /** @type {import('http-proxy-middleware/dist/types').Options} */
131
127
  const options = {
132
128
  target: 'http://www.example.org', // target host
133
129
  changeOrigin: true, // needed for virtual hosted sites
@@ -341,7 +337,7 @@ Subscribe to [http-proxy events](https://github.com/nodejitsu/node-http-proxy#li
341
337
  ```javascript
342
338
  function onOpen(proxySocket) {
343
339
  // listen for messages coming FROM the target here
344
- proxySocket.on('data', hybiParseAndLogMessage);
340
+ proxySocket.on('data', hybridParseAndLogMessage);
345
341
  }
346
342
  ```
347
343
 
@@ -586,6 +582,9 @@ $ yarn test
586
582
 
587
583
  # code coverage
588
584
  $ yarn cover
585
+
586
+ # check spelling mistakes
587
+ $ yarn spellcheck
589
588
  ```
590
589
 
591
590
  ## Changelog
@@ -596,4 +595,4 @@ $ yarn cover
596
595
 
597
596
  The MIT License (MIT)
598
597
 
599
- Copyright (c) 2015-2021 Steven Chim
598
+ 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');
@@ -19,7 +19,7 @@ function fixRequestBody(proxyReq, req) {
19
19
  if (contentType && contentType.includes('application/json')) {
20
20
  writeBody(JSON.stringify(requestBody));
21
21
  }
22
- if (contentType === 'application/x-www-form-urlencoded') {
22
+ if (contentType && contentType.includes('application/x-www-form-urlencoded')) {
23
23
  writeBody(querystring.stringify(requestBody));
24
24
  }
25
25
  }
@@ -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.4",
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,51 @@
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.2.1",
57
+ "@commitlint/config-conventional": "16.2.1",
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.18",
63
+ "@types/supertest": "2.0.11",
64
+ "@types/ws": "8.2.2",
65
+ "@typescript-eslint/eslint-plugin": "5.12.0",
66
+ "@typescript-eslint/parser": "5.12.0",
67
+ "body-parser": "1.19.2",
68
+ "browser-sync": "2.27.7",
69
+ "connect": "3.7.0",
70
+ "eslint": "8.9.0",
71
+ "eslint-config-prettier": "8.3.0",
72
+ "eslint-plugin-prettier": "4.0.0",
73
+ "express": "4.17.3",
74
+ "get-port": "5.1.1",
75
+ "husky": "7.0.4",
76
+ "jest": "27.5.1",
77
+ "lint-staged": "12.3.4",
78
+ "mockttp": "2.6.0",
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.5.0"
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
+ },
96
+ "peerDependenciesMeta": {
97
+ "@types/express": {
98
+ "optional": true
99
+ }
100
+ },
91
101
  "engines": {
92
102
  "node": ">=12.0.0"
93
103
  },