http-proxy-middleware
Advanced tools
Comparing version 2.0.0 to 2.0.1
/// <reference types="node" /> | ||
import { ClientRequest } from 'http'; | ||
import type { Request } from '../types'; | ||
import type * as http from 'http'; | ||
/** | ||
* Fix proxied body if bodyParser is involved. | ||
*/ | ||
export declare function fixRequestBody(proxyReq: ClientRequest, req: Request): void; | ||
export declare function fixRequestBody(proxyReq: http.ClientRequest, req: http.IncomingMessage): void; |
@@ -9,3 +9,4 @@ "use strict"; | ||
function fixRequestBody(proxyReq, req) { | ||
if (!req.body || !Object.keys(req.body).length) { | ||
const requestBody = req.body; | ||
if (!requestBody || !Object.keys(requestBody).length) { | ||
return; | ||
@@ -20,8 +21,8 @@ } | ||
if (contentType && contentType.includes('application/json')) { | ||
writeBody(JSON.stringify(req.body)); | ||
writeBody(JSON.stringify(requestBody)); | ||
} | ||
if (contentType === 'application/x-www-form-urlencoded') { | ||
writeBody(querystring.stringify(req.body)); | ||
writeBody(querystring.stringify(requestBody)); | ||
} | ||
} | ||
exports.fixRequestBody = fixRequestBody; |
@@ -0,6 +1,11 @@ | ||
/** | ||
* Based on definition by DefinitelyTyped: | ||
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6f529c6c67a447190f86bfbf894d1061e41e07b7/types/http-proxy-middleware/index.d.ts | ||
*/ | ||
/// <reference types="node" /> | ||
import * as express from 'express'; | ||
import * as http from 'http'; | ||
import * as httpProxy from 'http-proxy'; | ||
import * as net from 'net'; | ||
import type * as express from 'express'; | ||
import type * as http from 'http'; | ||
import type * as httpProxy from 'http-proxy'; | ||
import type * as net from 'net'; | ||
import type * as url from 'url'; | ||
export interface Request extends express.Request { | ||
@@ -22,9 +27,9 @@ } | ||
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent'; | ||
logProvider?(provider: LogProvider): LogProvider; | ||
onError?(err: Error, req: Request, res: Response): void; | ||
onProxyRes?(proxyRes: http.IncomingMessage, req: Request, res: Response): void; | ||
onProxyReq?(proxyReq: http.ClientRequest, req: Request, res: Response): void; | ||
onProxyReqWs?(proxyReq: http.ClientRequest, req: Request, socket: net.Socket, options: httpProxy.ServerOptions, head: any): void; | ||
onOpen?(proxySocket: net.Socket): void; | ||
onClose?(res: Response, socket: net.Socket, head: any): void; | ||
logProvider?: LogProviderCallback; | ||
onError?: OnErrorCallback; | ||
onProxyRes?: OnProxyResCallback; | ||
onProxyReq?: OnProxyReqCallback; | ||
onProxyReqWs?: OnProxyReqWsCallback; | ||
onOpen?: OnOpenCallback; | ||
onClose?: OnCloseCallback; | ||
} | ||
@@ -39,2 +44,13 @@ interface LogProvider { | ||
declare type Logger = (...args: any[]) => void; | ||
export declare type LogProviderCallback = (provider: LogProvider) => LogProvider; | ||
/** | ||
* Use types based on the events listeners from http-proxy | ||
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/51504fd999031b7f025220fab279f1b2155cbaff/types/http-proxy/index.d.ts | ||
*/ | ||
export declare type OnErrorCallback = (err: Error, req: http.IncomingMessage, res: http.ServerResponse, target?: string | Partial<url.Url>) => void; | ||
export declare type OnProxyResCallback = (proxyRes: http.IncomingMessage, req: http.IncomingMessage, res: http.ServerResponse) => void; | ||
export declare type OnProxyReqCallback = (proxyReq: http.ClientRequest, req: http.IncomingMessage, res: http.ServerResponse, options: httpProxy.ServerOptions) => void; | ||
export declare type OnProxyReqWsCallback = (proxyReq: http.ClientRequest, req: http.IncomingMessage, socket: net.Socket, options: httpProxy.ServerOptions, head: any) => void; | ||
export declare type OnCloseCallback = (proxyRes: http.IncomingMessage, proxySocket: net.Socket, proxyHead: any) => void; | ||
export declare type OnOpenCallback = (proxySocket: net.Socket) => void; | ||
export {}; |
"use strict"; | ||
/* eslint-disable @typescript-eslint/no-empty-interface */ | ||
/** | ||
* Based on definition by DefinitelyTyped: | ||
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6f529c6c67a447190f86bfbf894d1061e41e07b7/types/http-proxy-middleware/index.d.ts | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
{ | ||
"name": "http-proxy-middleware", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "The one-liner node.js proxy middleware for connect, express and browser-sync", | ||
@@ -24,3 +24,3 @@ "main": "dist/index.js", | ||
"coverage": "jest --coverage --coverageReporters=lcov", | ||
"prepare": "yarn build && rm dist/tsconfig.tsbuildinfo" | ||
"prepare": "husky install && yarn build && rm dist/tsconfig.tsbuildinfo" | ||
}, | ||
@@ -55,30 +55,31 @@ "repository": { | ||
"devDependencies": { | ||
"@commitlint/cli": "^12.0.1", | ||
"@commitlint/config-conventional": "^12.0.1", | ||
"@commitlint/cli": "^12.1.4", | ||
"@commitlint/config-conventional": "^12.1.4", | ||
"@types/express": "4.17.7", | ||
"@types/is-glob": "^4.0.1", | ||
"@types/jest": "^26.0.22", | ||
"@types/jest": "^26.0.23", | ||
"@types/micromatch": "^4.0.1", | ||
"@types/node": "^14.14.37", | ||
"@types/supertest": "^2.0.10", | ||
"@types/ws": "^7.4.0", | ||
"@typescript-eslint/eslint-plugin": "^4.19.0", | ||
"@typescript-eslint/parser": "^4.19.0", | ||
"@types/node": "^15.6.2", | ||
"@types/supertest": "^2.0.11", | ||
"@types/ws": "^7.4.4", | ||
"@typescript-eslint/eslint-plugin": "^4.26.0", | ||
"@typescript-eslint/parser": "^4.26.0", | ||
"body-parser": "^1.19.0", | ||
"browser-sync": "^2.26.14", | ||
"connect": "^3.7.0", | ||
"eslint": "^7.23.0", | ||
"eslint-config-prettier": "^8.1.0", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"eslint": "^7.27.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"express": "^4.17.1", | ||
"husky": "^4.3.0", | ||
"jest": "^26.6.3", | ||
"lint-staged": "^10.5.4", | ||
"mockttp": "^1.2.0", | ||
"open": "^7.4.2", | ||
"prettier": "^2.2.1", | ||
"get-port": "^5.1.1", | ||
"husky": "^6.0.0", | ||
"jest": "^27.0.3", | ||
"lint-staged": "^11.0.0", | ||
"mockttp": "^1.2.2", | ||
"open": "^8.2.0", | ||
"prettier": "^2.3.0", | ||
"supertest": "^6.1.3", | ||
"ts-jest": "^26.5.4", | ||
"typescript": "^4.2.3", | ||
"ws": "^7.4.4" | ||
"ts-jest": "^27.0.2", | ||
"typescript": "^4.3.2", | ||
"ws": "^7.4.6" | ||
}, | ||
@@ -95,8 +96,2 @@ "dependencies": { | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS", | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"commitlint": { | ||
@@ -103,0 +98,0 @@ "extends": [ |
961
63577
29
31