http-proxy-middleware 4.0.0-beta.2 → 4.0.0-beta.3

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
@@ -5,7 +5,7 @@
5
5
  [![Known Vulnerabilities](https://snyk.io/test/github/chimurai/http-proxy-middleware/badge.svg)](https://snyk.io/test/github/chimurai/http-proxy-middleware)
6
6
  [![npm](https://img.shields.io/npm/v/http-proxy-middleware?color=%23CC3534&style=flat-square&logo=npm)](https://www.npmjs.com/package/http-proxy-middleware)
7
7
 
8
- Node.js proxying made simple. Configure proxy middleware with ease for [connect](https://github.com/senchalabs/connect), [express](https://github.com/expressjs/express), [next.js](https://github.com/vercel/next.js) and [many more](#compatible-servers).
8
+ Node.js proxying made simple. Configure proxy middleware with ease for [connect](https://github.com/senchalabs/connect), [express](https://github.com/expressjs/express), [next.js](https://github.com/vercel/next.js), [hono](https://github.com/honojs/hono) and [many more](#compatible-servers).
9
9
 
10
10
  Powered by [`httpxy`](https://github.com/unjs/httpxy). A maintained version of [http-proxy](https://github.com/http-party/node-http-proxy).
11
11
 
@@ -592,6 +592,7 @@ View the [recipes](https://github.com/chimurai/http-proxy-middleware/tree/master
592
592
 
593
593
  - [connect](https://www.npmjs.com/package/connect)
594
594
  - [express](https://www.npmjs.com/package/express)
595
+ - [hono](https://www.npmjs.com/package/@hono/node-server)
595
596
  - [next.js](https://www.npmjs.com/package/next)
596
597
  - [fastify](https://www.npmjs.com/package/fastify)
597
598
  - [browser-sync](https://www.npmjs.com/package/browser-sync)
@@ -0,0 +1,25 @@
1
+ import type { HttpBindings } from '@hono/node-server';
2
+ import type { MiddlewareHandler } from 'hono';
3
+ import { type Options } from './index.js';
4
+ /**
5
+ * Creates a Hono middleware that proxies requests using http-proxy-middleware.
6
+ *
7
+ * `@remarks`
8
+ * This middleware requires Hono to be running on Node.js via `@hono/node-server`.
9
+ * It uses `c.env.incoming` and `c.env.outgoing` which are only available with `HttpBindings`.
10
+ *
11
+ * `@experimental` This API is experimental and may change without a major version bump.
12
+ *
13
+ * `@example`
14
+ * ```ts
15
+ * import { serve } from '@hono/node-server';
16
+ * import { Hono } from 'hono';
17
+ * import { createHonoProxyMiddleware } from 'http-proxy-middleware';
18
+ *
19
+ * const app = new Hono();
20
+ * app.use('/api', createHonoProxyMiddleware({ target: 'http://example.com', changeOrigin: true }));
21
+ * serve(app);
22
+ */
23
+ export declare function createHonoProxyMiddleware(options: Options): MiddlewareHandler<{
24
+ Bindings: HttpBindings;
25
+ }>;
@@ -0,0 +1,42 @@
1
+ import { createProxyMiddleware } from './index.js';
2
+ import { getLogger } from './logger.js';
3
+ /**
4
+ * Creates a Hono middleware that proxies requests using http-proxy-middleware.
5
+ *
6
+ * `@remarks`
7
+ * This middleware requires Hono to be running on Node.js via `@hono/node-server`.
8
+ * It uses `c.env.incoming` and `c.env.outgoing` which are only available with `HttpBindings`.
9
+ *
10
+ * `@experimental` This API is experimental and may change without a major version bump.
11
+ *
12
+ * `@example`
13
+ * ```ts
14
+ * import { serve } from '@hono/node-server';
15
+ * import { Hono } from 'hono';
16
+ * import { createHonoProxyMiddleware } from 'http-proxy-middleware';
17
+ *
18
+ * const app = new Hono();
19
+ * app.use('/api', createHonoProxyMiddleware({ target: 'http://example.com', changeOrigin: true }));
20
+ * serve(app);
21
+ */
22
+ export function createHonoProxyMiddleware(options) {
23
+ const proxy = createProxyMiddleware(options);
24
+ const logger = getLogger(options);
25
+ return (c, next) => {
26
+ return new Promise((resolve, reject) => {
27
+ proxy(c.env.incoming, c.env.outgoing, (err) => {
28
+ if (err) {
29
+ reject(err);
30
+ }
31
+ else {
32
+ resolve();
33
+ }
34
+ });
35
+ })
36
+ .then(() => next())
37
+ .catch((err) => {
38
+ logger.error('Proxy error:', err);
39
+ return c.text('Proxy Error', 500);
40
+ });
41
+ };
42
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './factory.js';
2
+ export * from './factory-hono.js';
2
3
  export * from './handlers/index.js';
3
4
  export type { Plugin, Filter, Options, RequestHandler } from './types.js';
4
5
  /**
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './factory.js';
2
+ export * from './factory-hono.js';
2
3
  export * from './handlers/index.js';
3
4
  /**
4
5
  * Default plugins
@@ -1,4 +1,4 @@
1
- import { isPlainObject } from 'is-plain-object';
1
+ import isPlainObject from 'is-plain-obj';
2
2
  import { Debug } from './debug.js';
3
3
  import { ERRORS } from './errors.js';
4
4
  const debug = Debug.extend('path-rewriter');
package/dist/router.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isPlainObject } from 'is-plain-object';
1
+ import isPlainObject from 'is-plain-obj';
2
2
  import { Debug } from './debug.js';
3
3
  const debug = Debug.extend('router');
4
4
  export async function getTarget(req, config) {
package/dist/types.d.ts CHANGED
@@ -18,7 +18,7 @@ export interface OnProxyEvent<TReq extends http.IncomingMessage = http.IncomingM
18
18
  error?: (err: Error, req: TReq, res: TRes | net.Socket, target?: string | Partial<URL>) => void;
19
19
  proxyReq?: (proxyReq: http.ClientRequest, req: TReq, res: TRes, options: ProxyServerOptions) => void;
20
20
  proxyReqWs?: (proxyReq: http.ClientRequest, req: TReq, socket: net.Socket, options: ProxyServerOptions, head: any) => void;
21
- proxyRes?: (proxyRes: TReq, req: TReq, res: TRes) => void;
21
+ proxyRes?: (proxyRes: TReq, req: TReq, res: TRes) => void | Promise<void>;
22
22
  open?: (proxySocket: net.Socket) => void;
23
23
  close?: (proxyRes: TReq, proxySocket: net.Socket, proxyHead: any) => void;
24
24
  start?: (req: TReq, res: TRes, target: string | Partial<URL>) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "http-proxy-middleware",
3
3
  "type": "module",
4
- "version": "4.0.0-beta.2",
4
+ "version": "4.0.0-beta.3",
5
5
  "description": "The one-liner node.js proxy middleware for connect, express, next.js and more",
6
6
  "main": "dist/index.js",
7
7
  "exports": {
@@ -64,11 +64,12 @@
64
64
  },
65
65
  "homepage": "https://github.com/chimurai/http-proxy-middleware#readme",
66
66
  "devDependencies": {
67
- "@commitlint/cli": "20.4.2",
68
- "@commitlint/config-conventional": "20.4.2",
67
+ "@commitlint/cli": "20.5.0",
68
+ "@commitlint/config-conventional": "20.5.0",
69
69
  "@eslint/js": "10.0.1",
70
+ "@hono/node-server": "1.19.12",
70
71
  "@trivago/prettier-plugin-sort-imports": "6.0.2",
71
- "@types/debug": "4.1.12",
72
+ "@types/debug": "4.1.13",
72
73
  "@types/eslint": "9.6.1",
73
74
  "@types/express": "5.0.6",
74
75
  "@types/is-glob": "4.0.4",
@@ -76,30 +77,31 @@
76
77
  "@types/node": "24.10.2",
77
78
  "@types/supertest": "7.2.0",
78
79
  "@types/ws": "8.18.1",
79
- "@vitest/coverage-v8": "^4.1.2",
80
+ "@vitest/coverage-v8": "4.1.2",
80
81
  "body-parser": "2.2.2",
81
- "eslint": "10.0.2",
82
+ "eslint": "10.2.0",
82
83
  "express": "5.2.1",
83
- "get-port": "5.1.1",
84
- "globals": "17.3.0",
84
+ "get-port": "7.2.0",
85
+ "globals": "17.4.0",
86
+ "hono": "4.12.10",
85
87
  "husky": "9.1.7",
86
- "lint-staged": "16.3.0",
87
- "mockttp": "4.2.1",
88
- "open": "8.4.2",
88
+ "lint-staged": "16.4.0",
89
+ "mockttp": "4.3.0",
90
+ "open": "11.0.0",
89
91
  "patch-package": "8.0.1",
90
- "pkg-pr-new": "0.0.65",
92
+ "pkg-pr-new": "0.0.66",
91
93
  "prettier": "3.8.1",
92
94
  "supertest": "7.2.2",
93
- "typescript": "5.9.3",
94
- "typescript-eslint": "8.56.1",
95
- "vitest": "^4.1.2",
96
- "ws": "8.19.0"
95
+ "typescript": "6.0.2",
96
+ "typescript-eslint": "8.58.0",
97
+ "vitest": "4.1.2",
98
+ "ws": "8.20.0"
97
99
  },
98
100
  "dependencies": {
99
- "debug": "^4.3.6",
101
+ "debug": "^4.4.3",
100
102
  "httpxy": "^0.5.0",
101
103
  "is-glob": "^4.0.3",
102
- "is-plain-object": "^5.0.0",
104
+ "is-plain-obj": "^4.1.0",
103
105
  "micromatch": "^4.0.8"
104
106
  },
105
107
  "resolutions": {