Skip to content

Commit 4dcdeb0

Browse files
committed
fix: improve port handling logic in InboundsService
- Enhanced the logic for determining the port from configuration, supporting various input types including number, string, and array. - Ensured that the port defaults to 0 when no valid input is provided, improving robustness in configuration handling.
1 parent 344e71f commit 4dcdeb0

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/modules/inbounds/inbounds.service.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,20 @@ export class InboundsService {
4747
.getConfig()
4848
.inbounds.find((i) => i.tag === inbound.tag);
4949

50-
const port = Number(rawFromConfig!.port! || 0);
50+
let port = 0;
51+
52+
if (typeof rawFromConfig?.port === 'number') {
53+
port = rawFromConfig.port;
54+
} else if (typeof rawFromConfig?.port === 'string') {
55+
if (Array.isArray(rawFromConfig.port)) {
56+
port = Number(rawFromConfig.port[0]);
57+
} else if (rawFromConfig.port.includes(',')) {
58+
const ports = rawFromConfig.port.split(',');
59+
port = Number(ports[0]);
60+
} else {
61+
port = 0;
62+
}
63+
}
5164

5265
result.push(new BaseInboundEntity(inbound, port));
5366
}
@@ -93,7 +106,20 @@ export class InboundsService {
93106
.getConfig()
94107
.inbounds.find((i) => i.tag === inbound.tag);
95108

96-
const port = Number(rawFromConfig!.port! || 0);
109+
let port = 0;
110+
111+
if (typeof rawFromConfig?.port === 'number') {
112+
port = rawFromConfig.port;
113+
} else if (typeof rawFromConfig?.port === 'string') {
114+
if (Array.isArray(rawFromConfig.port)) {
115+
port = Number(rawFromConfig.port[0]);
116+
} else if (rawFromConfig.port.includes(',')) {
117+
const ports = rawFromConfig.port.split(',');
118+
port = Number(ports[0]);
119+
} else {
120+
port = 0;
121+
}
122+
}
97123

98124
result.push(
99125
new GetFullInboundsResponseModel(

0 commit comments

Comments
 (0)