From 74919807593337d4ec6016e8a0b358c3e804bcc5 Mon Sep 17 00:00:00 2001 From: Steven Chim <655241+chimurai@users.noreply.github.com> Date: Sun, 6 Jul 2025 17:23:35 +0000 Subject: [PATCH] chore(refactor): use node: protocol imports --- package.json | 2 +- src/factory.ts | 2 +- src/handlers/fix-request-body.ts | 4 ++-- src/handlers/response-interceptor.ts | 4 ++-- src/http-proxy-middleware.ts | 7 ++++--- src/legacy/create-proxy-middleware.ts | 2 +- src/legacy/options-adapter.ts | 2 +- src/legacy/types.ts | 2 +- src/path-filter.ts | 5 +++-- src/plugins/default/error-response-plugin.ts | 4 ++-- src/plugins/default/logger-plugin.ts | 3 +-- src/types.ts | 5 +++-- test/e2e/http-proxy-middleware.spec.ts | 3 ++- test/e2e/http-server.spec.ts | 3 ++- test/e2e/test-kit.ts | 2 +- test/e2e/websocket.spec.ts | 3 ++- test/types.spec.ts | 3 ++- test/unit/fix-request-body.spec.ts | 6 +++--- test/unit/path-filter.spec.ts | 2 +- test/unit/response-interceptor.spec.ts | 4 ++-- 20 files changed, 37 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 42c8b9b9..9759e92d 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,7 @@ "micromatch": "^4.0.8" }, "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + "node": "^14.18.0 || ^16.10.0 || >=18.0.0" }, "commitlint": { "extends": [ diff --git a/src/factory.ts b/src/factory.ts index 305fc394..daa5b20c 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -1,4 +1,4 @@ -import type * as http from 'http'; +import type * as http from 'node:http'; import { HttpProxyMiddleware } from './http-proxy-middleware'; import type { NextFunction, Options, RequestHandler } from './types'; diff --git a/src/handlers/fix-request-body.ts b/src/handlers/fix-request-body.ts index 371355e9..cc47e68f 100644 --- a/src/handlers/fix-request-body.ts +++ b/src/handlers/fix-request-body.ts @@ -1,5 +1,5 @@ -import type * as http from 'http'; -import * as querystring from 'querystring'; +import type * as http from 'node:http'; +import * as querystring from 'node:querystring'; export type BodyParserLikeRequest = http.IncomingMessage & { body?: any }; diff --git a/src/handlers/response-interceptor.ts b/src/handlers/response-interceptor.ts index 3751914b..67a53027 100644 --- a/src/handlers/response-interceptor.ts +++ b/src/handlers/response-interceptor.ts @@ -1,5 +1,5 @@ -import type * as http from 'http'; -import * as zlib from 'zlib'; +import type * as http from 'node:http'; +import * as zlib from 'node:zlib'; import { Debug } from '../debug'; import { getFunctionName } from '../utils/function'; diff --git a/src/http-proxy-middleware.ts b/src/http-proxy-middleware.ts index b4225659..6fe301c0 100644 --- a/src/http-proxy-middleware.ts +++ b/src/http-proxy-middleware.ts @@ -1,7 +1,8 @@ -import type * as http from 'http'; +import type * as http from 'node:http'; +import type * as https from 'node:https'; +import type * as net from 'node:net'; + import * as httpProxy from 'http-proxy'; -import type * as https from 'https'; -import type * as net from 'net'; import { verifyConfig } from './configuration'; import { Debug as debug } from './debug'; diff --git a/src/legacy/create-proxy-middleware.ts b/src/legacy/create-proxy-middleware.ts index fdbc151f..db351168 100644 --- a/src/legacy/create-proxy-middleware.ts +++ b/src/legacy/create-proxy-middleware.ts @@ -1,4 +1,4 @@ -import type * as http from 'http'; +import type * as http from 'node:http'; import { Debug } from '../debug'; import { createProxyMiddleware } from '../factory'; diff --git a/src/legacy/options-adapter.ts b/src/legacy/options-adapter.ts index 7225f272..79495cf2 100644 --- a/src/legacy/options-adapter.ts +++ b/src/legacy/options-adapter.ts @@ -1,4 +1,4 @@ -import * as url from 'url'; +import * as url from 'node:url'; import { Debug } from '../debug'; import { getLogger } from '../logger'; diff --git a/src/legacy/types.ts b/src/legacy/types.ts index 66ce3e71..9db2762b 100644 --- a/src/legacy/types.ts +++ b/src/legacy/types.ts @@ -1,4 +1,4 @@ -import type * as http from 'http'; +import type * as http from 'node:http'; import { Options } from '../types'; diff --git a/src/path-filter.ts b/src/path-filter.ts index 62316bfa..b1553a88 100644 --- a/src/path-filter.ts +++ b/src/path-filter.ts @@ -1,7 +1,8 @@ -import type * as http from 'http'; +import type * as http from 'node:http'; +import * as url from 'node:url'; + import * as isGlob from 'is-glob'; import * as micromatch from 'micromatch'; -import * as url from 'url'; import { ERRORS } from './errors'; import type { Filter } from './types'; diff --git a/src/plugins/default/error-response-plugin.ts b/src/plugins/default/error-response-plugin.ts index 8fdefeb3..3af7aca7 100644 --- a/src/plugins/default/error-response-plugin.ts +++ b/src/plugins/default/error-response-plugin.ts @@ -1,5 +1,5 @@ -import type * as http from 'http'; -import type { Socket } from 'net'; +import type * as http from 'node:http'; +import type { Socket } from 'node:net'; import { getStatusCode } from '../../status-code'; import { Plugin } from '../../types'; diff --git a/src/plugins/default/logger-plugin.ts b/src/plugins/default/logger-plugin.ts index 3d5d1bad..ddfff844 100644 --- a/src/plugins/default/logger-plugin.ts +++ b/src/plugins/default/logger-plugin.ts @@ -1,6 +1,5 @@ import type { IncomingMessage } from 'node:http'; - -import { URL } from 'url'; +import { URL } from 'node:url'; import { getLogger } from '../../logger'; import { Plugin } from '../../types'; diff --git a/src/types.ts b/src/types.ts index bc416eb7..dbddb4ec 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,9 +2,10 @@ * Based on definition by DefinitelyTyped: * https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6f529c6c67a447190f86bfbf894d1061e41e07b7/types/http-proxy-middleware/index.d.ts */ -import type * as http from 'http'; +import type * as http from 'node:http'; +import type * as net from 'node:net'; + import type * as httpProxy from 'http-proxy'; -import type * as net from 'net'; export type NextFunction void> = T; diff --git a/test/e2e/http-proxy-middleware.spec.ts b/test/e2e/http-proxy-middleware.spec.ts index 40c7ee5f..7e167e40 100644 --- a/test/e2e/http-proxy-middleware.spec.ts +++ b/test/e2e/http-proxy-middleware.spec.ts @@ -1,6 +1,7 @@ +import type * as http from 'node:http'; + import * as bodyParser from 'body-parser'; import type * as express from 'express'; -import type * as http from 'http'; import { CompletedRequest, Mockttp, getLocal } from 'mockttp'; import * as request from 'supertest'; diff --git a/test/e2e/http-server.spec.ts b/test/e2e/http-server.spec.ts index 50d5f4e2..f38e13cd 100644 --- a/test/e2e/http-server.spec.ts +++ b/test/e2e/http-server.spec.ts @@ -1,4 +1,5 @@ -import * as http from 'http'; +import * as http from 'node:http'; + import * as request from 'supertest'; import { createProxyMiddleware } from './test-kit'; diff --git a/test/e2e/test-kit.ts b/test/e2e/test-kit.ts index e160f85f..d1e857f4 100644 --- a/test/e2e/test-kit.ts +++ b/test/e2e/test-kit.ts @@ -1,5 +1,5 @@ import * as express from 'express'; -import { Express, RequestHandler } from 'express'; +import type { Express, RequestHandler } from 'express'; export { createProxyMiddleware, responseInterceptor, fixRequestBody } from '../../src/index'; diff --git a/test/e2e/websocket.spec.ts b/test/e2e/websocket.spec.ts index c8525ba8..f2408cfb 100644 --- a/test/e2e/websocket.spec.ts +++ b/test/e2e/websocket.spec.ts @@ -1,5 +1,6 @@ +import * as http from 'node:http'; + import * as getPort from 'get-port'; -import * as http from 'http'; import { WebSocket, WebSocketServer } from 'ws'; import type { RequestHandler } from '../../src/types'; diff --git a/test/types.spec.ts b/test/types.spec.ts index 1f451e07..6f306f9b 100644 --- a/test/types.spec.ts +++ b/test/types.spec.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions */ +import * as http from 'node:http'; + import * as express from 'express'; -import * as http from 'http'; import { fixRequestBody, createProxyMiddleware as middleware, responseInterceptor } from '../src'; import type { Options, RequestHandler } from '../src/types'; diff --git a/test/unit/fix-request-body.spec.ts b/test/unit/fix-request-body.spec.ts index baa75262..4615c67c 100644 --- a/test/unit/fix-request-body.spec.ts +++ b/test/unit/fix-request-body.spec.ts @@ -1,6 +1,6 @@ -import { ClientRequest, IncomingMessage, ServerResponse } from 'http'; -import { Socket } from 'net'; -import * as querystring from 'querystring'; +import { ClientRequest, IncomingMessage, ServerResponse } from 'node:http'; +import { Socket } from 'node:net'; +import * as querystring from 'node:querystring'; import { BodyParserLikeRequest, fixRequestBody } from '../../src/handlers/fix-request-body'; diff --git a/test/unit/path-filter.spec.ts b/test/unit/path-filter.spec.ts index 44993f0a..884523ec 100644 --- a/test/unit/path-filter.spec.ts +++ b/test/unit/path-filter.spec.ts @@ -1,4 +1,4 @@ -import type * as http from 'http'; +import type * as http from 'node:http'; import { matchPathFilter } from '../../src/path-filter'; diff --git a/test/unit/response-interceptor.spec.ts b/test/unit/response-interceptor.spec.ts index 588b73f8..fd9b5244 100644 --- a/test/unit/response-interceptor.spec.ts +++ b/test/unit/response-interceptor.spec.ts @@ -1,5 +1,5 @@ -import { IncomingMessage, ServerResponse } from 'http'; -import { Socket } from 'net'; +import { IncomingMessage, ServerResponse } from 'node:http'; +import { Socket } from 'node:net'; import { responseInterceptor } from '../../src/handlers/response-interceptor';