Skip to content

Commit ac7fd57

Browse files
committed
vender part of requires-port that we use
- so can have type checks - remove a runtime dep that isn't maintained
1 parent 0e93bb6 commit ac7fd57

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

lib/http-proxy/common.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as required from "requires-port";
21
import type { ProxyTargetDetailed, ServerOptions } from "./index";
32
import { type IncomingMessage as Request } from "http";
43
import { TLSSocket } from "tls";
@@ -235,3 +234,24 @@ function getPath(url?: string): string {
235234
const u = new URL(url ?? "", "http://dummy");
236235
return `${u.pathname ?? ""}${u.search ?? ""}`;
237236
}
237+
238+
// vendor simplified version of https://www.npmjs.com/package/requires-port to
239+
// reduce dep and add typescript.
240+
function required(port: number, protocol: string): boolean {
241+
protocol = protocol.split(":")[0];
242+
port = +port;
243+
244+
if (!port) return false;
245+
246+
switch (protocol) {
247+
case "http":
248+
case "ws":
249+
return port !== 80;
250+
251+
case "https":
252+
case "wss":
253+
return port !== 443;
254+
}
255+
256+
return port !== 0;
257+
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
"main": "dist/lib/index.js",
1616
"dependencies": {
1717
"debug": "^4.4.0",
18-
"follow-redirects": "^1.15.9",
19-
"requires-port": "^1.0.0"
18+
"follow-redirects": "^1.15.9"
2019
},
2120
"devDependencies": {
2221
"@types/debug": "^4.1.12",

pnpm-lock.yaml

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)