feat(settings): use webListen URI format for Web API address

- rename webPort field/label to webListen (Web API 监听地址)
- seed initial form state from webListen with legacy webPort fallback
- save webListen URI string while deriving legacy webPort integer for
  backend compatibility
This commit is contained in:
2026-08-26 19:42:20 +08:00
parent d4250fce31
commit f38d640ac4
2 changed files with 21 additions and 9 deletions
+20 -9
View File
@@ -151,6 +151,9 @@ function SettingsForm({
...initialConfig,
TCPListen: toAddrString(initialConfig.TCPListen),
UDPListen: toAddrString(initialConfig.UDPListen),
webListen:
initialConfig.webListen ??
(initialConfig.webPort ? `http://0.0.0.0:${initialConfig.webPort}` : 'http://0.0.0.0:4665'),
}))
const [tunEnabled, setTunEnabled] = useState<boolean>(() =>
initialConfig.enableTUN ??
@@ -209,9 +212,19 @@ function SettingsForm({
form.denyConnectionBroadcast ??
form.denyLineTableBroadcast ??
false
const webListen = form.webListen?.trim() || 'http://0.0.0.0:4665'
let webPort = 4665
try {
const parsedPort = new URL(webListen).port
if (parsedPort) webPort = parseInt(parsedPort, 10)
} catch {
// Java backend validates the canonical listen address.
}
const updatedConfig: Record<string, unknown> = {
...form,
webListen,
webPort,
externalEndpoints: updatedExternalEndpoints,
openConnections: updatedExternalEndpoints,
autoConnections: updatedAutoConnections,
@@ -485,23 +498,21 @@ function SettingsForm({
)}
<Field>
<FieldLabel htmlFor="webPort">Web </FieldLabel>
<FieldLabel htmlFor="webListen">Web API </FieldLabel>
<Input
id="webPort"
type="number"
min={1}
max={65535}
placeholder="4665"
value={form.webPort ?? 4665}
id="webListen"
type="text"
placeholder="http://0.0.0.0:4665"
value={form.webListen ?? 'http://0.0.0.0:4665'}
onChange={(e) =>
setForm((prev) => ({
...prev,
webPort: parseInt(e.target.value) || 4665,
webListen: e.target.value,
}))
}
/>
<FieldDescription>
Web API 4665
Web API http://0.0.0.0:4665
</FieldDescription>
</Field>
+1
View File
@@ -109,6 +109,7 @@ export interface KLALBControllerConfig {
enableTUN?: boolean
TUNName?: string | null
webUI?: boolean
webListen?: string
webPort?: number
nogui?: boolean
TCPListen?: string