http-proxy-middleware
Advanced tools
+1
-1
@@ -10,2 +10,2 @@ "use strict"; | ||
| ERRORS["ERR_PATH_REWRITER_CONFIG"] = "[HPM] Invalid pathRewrite config. Expecting object with pathRewrite config or a rewrite function"; | ||
| })(ERRORS = exports.ERRORS || (exports.ERRORS = {})); | ||
| })(ERRORS || (exports.ERRORS = ERRORS = {})); |
@@ -6,11 +6,10 @@ "use strict"; | ||
| function getPlugins(options) { | ||
| var _a, _b; | ||
| // don't load default errorResponsePlugin if user has specified their own | ||
| const maybeErrorResponsePlugin = !!((_a = options.on) === null || _a === void 0 ? void 0 : _a.error) ? [] : [default_1.errorResponsePlugin]; | ||
| const maybeErrorResponsePlugin = !!options.on?.error ? [] : [default_1.errorResponsePlugin]; | ||
| const defaultPlugins = !!options.ejectPlugins | ||
| ? [] // no default plugins when ejecting | ||
| : [default_1.debugProxyErrorsPlugin, default_1.proxyEventsPlugin, default_1.loggerPlugin, ...maybeErrorResponsePlugin]; | ||
| const userPlugins = (_b = options.plugins) !== null && _b !== void 0 ? _b : []; | ||
| const userPlugins = options.plugins ?? []; | ||
| return [...defaultPlugins, ...userPlugins]; | ||
| } | ||
| exports.getPlugins = getPlugins; |
| /// <reference types="node" /> | ||
| import type * as http from 'http'; | ||
| export declare type BodyParserLikeRequest = http.IncomingMessage & { | ||
| export type BodyParserLikeRequest = http.IncomingMessage & { | ||
| body: any; | ||
@@ -5,0 +5,0 @@ }; |
| /// <reference types="node" /> | ||
| /// <reference types="node" /> | ||
| import type * as http from 'http'; | ||
| declare type Interceptor<TReq = http.IncomingMessage, TRes = http.ServerResponse> = (buffer: Buffer, proxyRes: TReq, req: TReq, res: TRes) => Promise<Buffer | string>; | ||
| type Interceptor<TReq = http.IncomingMessage, TRes = http.ServerResponse> = (buffer: Buffer, proxyRes: TReq, req: TReq, res: TRes) => Promise<Buffer | string>; | ||
| /** | ||
@@ -6,0 +6,0 @@ * Intercept responses from upstream. |
@@ -17,4 +17,3 @@ "use strict"; | ||
| // https://github.com/Microsoft/TypeScript/wiki/'this'-in-TypeScript#red-flags-for-this | ||
| this.middleware = async (req, res, next) => { | ||
| var _a, _b; | ||
| this.middleware = (async (req, res, next) => { | ||
| if (this.shouldProxy(this.proxyOptions.pathFilter, req)) { | ||
@@ -41,3 +40,3 @@ try { | ||
| */ | ||
| const server = (_b = (((_a = req.socket) !== null && _a !== void 0 ? _a : req.connection))) === null || _b === void 0 ? void 0 : _b.server; | ||
| const server = (req.socket ?? req.connection)?.server; | ||
| if (server && !this.serverOnCloseSubscribed) { | ||
@@ -54,3 +53,3 @@ server.on('close', () => { | ||
| } | ||
| }; | ||
| }); | ||
| this.catchUpgradeRequest = (server) => { | ||
@@ -57,0 +56,0 @@ if (!this.wsInternalSubscribed) { |
@@ -21,3 +21,3 @@ "use strict"; | ||
| function legacyOptionsAdapter(legacyContext, legacyOptions) { | ||
| let options; | ||
| let options = {}; | ||
| let logger; | ||
@@ -27,3 +27,6 @@ // https://github.com/chimurai/http-proxy-middleware/pull/716 | ||
| throw new Error(`Shorthand syntax is removed from legacyCreateProxyMiddleware(). | ||
| Please use "legacyCreateProxyMiddleware({ target: 'http://www.example.org' })" instead.`); | ||
| Please use "legacyCreateProxyMiddleware({ target: 'http://www.example.org' })" instead. | ||
| More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md#removed-shorthand-usage | ||
| `); | ||
| } | ||
@@ -42,3 +45,3 @@ // detect old "context" argument and convert to "options.pathFilter" | ||
| More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md | ||
| More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md#removed-context-argument | ||
| `); | ||
@@ -50,2 +53,5 @@ } | ||
| } | ||
| else { | ||
| logger = getLegacyLogger({}); | ||
| } | ||
| // map old event names to new event names | ||
@@ -66,3 +72,3 @@ // https://github.com/chimurai/http-proxy-middleware/pull/745/files#diff-c54113cf61ec99691748a3890bfbeb00e10efb3f0a76f03a0fd9ec49072e410aL48-L53 | ||
| More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md | ||
| More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md#refactored-proxy-events | ||
| `); | ||
@@ -85,3 +91,3 @@ } | ||
| More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md | ||
| More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md#removed-logprovider-and-loglevel-options | ||
| `); | ||
@@ -88,0 +94,0 @@ } |
| /// <reference types="node" /> | ||
| import type { Filter } from './types'; | ||
| import type * as http from 'http'; | ||
| export declare function matchPathFilter<TReq = http.IncomingMessage>(pathFilter: Filter<TReq>, uri: string, req: http.IncomingMessage): boolean; | ||
| export declare function matchPathFilter<TReq = http.IncomingMessage>(pathFilter: Filter<TReq> | undefined, uri: string | undefined, req: http.IncomingMessage): boolean; |
@@ -42,3 +42,3 @@ "use strict"; | ||
| const pathname = getUrlPathName(uri); | ||
| return pathname.indexOf(pathFilter) === 0; | ||
| return pathname?.indexOf(pathFilter) === 0; | ||
| } | ||
@@ -45,0 +45,0 @@ function matchSingleGlobPath(pattern, uri) { |
@@ -11,3 +11,3 @@ "use strict"; | ||
| } | ||
| if (res.writeHead && !res.headersSent) { | ||
| if ('writeHead' in res && !res.headersSent) { | ||
| const statusCode = (0, status_code_1.getStatusCode)(err.code); | ||
@@ -14,0 +14,0 @@ res.writeHead(statusCode); |
@@ -8,6 +8,5 @@ "use strict"; | ||
| proxyServer.on('error', (err, req, res, target) => { | ||
| var _a; | ||
| const hostname = (_a = req === null || req === void 0 ? void 0 : req.headers) === null || _a === void 0 ? void 0 : _a.host; | ||
| const requestHref = `${hostname}${req === null || req === void 0 ? void 0 : req.url}`; | ||
| const targetHref = `${target === null || target === void 0 ? void 0 : target.href}`; // target is undefined when websocket errors | ||
| const hostname = req?.headers?.host; | ||
| const requestHref = `${hostname}${req?.url}`; | ||
| const targetHref = `${target?.href}`; // target is undefined when websocket errors | ||
| const errorMessage = '[HPM] Error occurred while proxying request %s to %s [%s] (%s)'; | ||
@@ -25,6 +24,5 @@ const errReference = 'https://nodejs.org/api/errors.html#errors_common_system_errors'; // link to Node Common Systems Errors page | ||
| proxyServer.on('proxyRes', (proxyRes, req, res) => { | ||
| var _a; | ||
| // BrowserSync uses req.originalUrl | ||
| // Next.js doesn't have req.baseUrl | ||
| const originalUrl = (_a = req.originalUrl) !== null && _a !== void 0 ? _a : `${req.baseUrl || ''}${req.url}`; | ||
| const originalUrl = req.originalUrl ?? `${req.baseUrl || ''}${req.url}`; | ||
| const exchange = `[HPM] ${req.method} ${originalUrl} -> ${proxyRes.req.protocol}//${proxyRes.req.host}${proxyRes.req.path} [${proxyRes.statusCode}]`; | ||
@@ -31,0 +29,0 @@ logger.info(exchange); |
+6
-5
@@ -8,11 +8,12 @@ /** | ||
| /// <reference types="node" /> | ||
| /// <reference types="node" /> | ||
| import type * as http from 'http'; | ||
| import type * as httpProxy from 'http-proxy'; | ||
| import type * as net from 'net'; | ||
| export declare type NextFunction<T = (err?: any) => void> = T; | ||
| export type NextFunction<T = (err?: any) => void> = T; | ||
| export interface RequestHandler<TReq = http.IncomingMessage, TRes = http.ServerResponse, TNext = NextFunction> { | ||
| (req: TReq, res: TRes, next?: TNext): void | Promise<void>; | ||
| upgrade?: (req: http.IncomingMessage, socket: net.Socket, head: any) => void; | ||
| upgrade: (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => void; | ||
| } | ||
| export declare type Filter<TReq = http.IncomingMessage> = string | string[] | ((pathname: string, req: TReq) => boolean); | ||
| export type Filter<TReq = http.IncomingMessage> = string | string[] | ((pathname: string, req: TReq) => boolean); | ||
| export interface Plugin<TReq = http.IncomingMessage, TRes = http.ServerResponse> { | ||
@@ -32,3 +33,3 @@ (proxyServer: httpProxy<TReq, TRes>, options: Options<TReq, TRes>): void; | ||
| } | ||
| export declare type Logger = Pick<Console, 'info' | 'warn' | 'error'>; | ||
| export type Logger = Pick<Console, 'info' | 'warn' | 'error'>; | ||
| export interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse> extends httpProxy.ServerOptions { | ||
@@ -57,3 +58,3 @@ /** | ||
| [regexp: string]: string; | ||
| } | ((path: string, req: TReq) => string) | ((path: string, req: TReq) => Promise<string>); | ||
| } | ((path: string, req: TReq) => string | undefined) | ((path: string, req: TReq) => Promise<string>); | ||
| /** | ||
@@ -60,0 +61,0 @@ * Access the internal http-proxy server instance to customize behavior |
+28
-28
| { | ||
| "name": "http-proxy-middleware", | ||
| "version": "3.0.0-beta.1", | ||
| "version": "3.0.0", | ||
| "description": "The one-liner node.js proxy middleware for connect, express, next.js and more", | ||
@@ -21,3 +21,3 @@ "main": "dist/index.js", | ||
| "coverage": "jest --coverage", | ||
| "prepare": "husky install", | ||
| "prepare": "husky", | ||
| "prepack": "yarn clean && yarn test && yarn build", | ||
@@ -55,32 +55,32 @@ "spellcheck": "npx --yes cspell --show-context --show-suggestions '**/*.*'" | ||
| "devDependencies": { | ||
| "@commitlint/cli": "17.4.4", | ||
| "@commitlint/config-conventional": "17.4.4", | ||
| "@types/debug": "4.1.7", | ||
| "@types/express": "4.17.17", | ||
| "@types/is-glob": "4.0.2", | ||
| "@types/jest": "29.4.0", | ||
| "@types/micromatch": "4.0.2", | ||
| "@types/node": "18.14.5", | ||
| "@commitlint/cli": "17.7.1", | ||
| "@commitlint/config-conventional": "17.7.0", | ||
| "@types/debug": "4.1.12", | ||
| "@types/express": "4.17.21", | ||
| "@types/is-glob": "4.0.4", | ||
| "@types/jest": "29.5.12", | ||
| "@types/micromatch": "4.0.6", | ||
| "@types/node": "20.11.30", | ||
| "@types/supertest": "2.0.12", | ||
| "@types/ws": "8.5.4", | ||
| "@typescript-eslint/eslint-plugin": "5.54.0", | ||
| "@typescript-eslint/parser": "5.54.0", | ||
| "@types/ws": "8.5.10", | ||
| "@typescript-eslint/eslint-plugin": "7.4.0", | ||
| "@typescript-eslint/parser": "7.4.0", | ||
| "body-parser": "1.20.2", | ||
| "browser-sync": "2.28.1", | ||
| "browser-sync": "3.0.2", | ||
| "connect": "3.7.0", | ||
| "eslint": "8.35.0", | ||
| "eslint-config-prettier": "8.6.0", | ||
| "eslint-plugin-prettier": "4.2.1", | ||
| "express": "4.18.2", | ||
| "eslint": "8.57.0", | ||
| "eslint-config-prettier": "9.1.0", | ||
| "eslint-plugin-prettier": "5.1.3", | ||
| "express": "4.19.2", | ||
| "get-port": "5.1.1", | ||
| "husky": "8.0.3", | ||
| "jest": "29.4.3", | ||
| "lint-staged": "13.1.2", | ||
| "mockttp": "3.7.0", | ||
| "husky": "9.0.11", | ||
| "jest": "29.7.0", | ||
| "lint-staged": "15.2.2", | ||
| "mockttp": "3.10.1", | ||
| "open": "8.4.2", | ||
| "prettier": "2.8.4", | ||
| "supertest": "6.3.3", | ||
| "ts-jest": "29.0.5", | ||
| "typescript": "4.9.5", | ||
| "ws": "8.12.1" | ||
| "prettier": "3.2.5", | ||
| "supertest": "6.3.4", | ||
| "ts-jest": "29.1.2", | ||
| "typescript": "5.4.3", | ||
| "ws": "8.16.0" | ||
| }, | ||
@@ -96,3 +96,3 @@ "dependencies": { | ||
| "engines": { | ||
| "node": ">=12.0.0" | ||
| "node": "^14.15.0 || ^16.10.0 || >=18.0.0" | ||
| }, | ||
@@ -99,0 +99,0 @@ "commitlint": { |
+5
-5
@@ -5,3 +5,3 @@ # http-proxy-middleware | ||
| [](https://coveralls.io/r/chimurai/http-proxy-middleware) | ||
| [](https://security.snyk.io/package/npm/http-proxy-middleware) | ||
| [](https://snyk.io/test/github/chimurai/http-proxy-middleware) | ||
| [](https://www.npmjs.com/package/http-proxy-middleware) | ||
@@ -43,3 +43,3 @@ | ||
| changeOrigin: true, | ||
| }) | ||
| }), | ||
| ); | ||
@@ -66,3 +66,3 @@ | ||
| changeOrigin: true, | ||
| }) | ||
| }), | ||
| ); | ||
@@ -170,3 +170,3 @@ | ||
| pathFilter: '/api/proxy-only-this-path', | ||
| }) | ||
| }), | ||
| ); | ||
@@ -496,3 +496,3 @@ ``` | ||
| }, | ||
| next | ||
| next, | ||
| ); | ||
@@ -499,0 +499,0 @@ }; |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
1322
0.15%0
-100%80043
-0.23%