Skip to content

Commit ad68110

Browse files
committed
feat: add Docker environment detection to network interface handling
1 parent b138609 commit ad68110

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/webui/BE/routes/config.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getConfigUtil, webuiTokenUtil } from '@/common/config'
55
import { selfInfo } from '@/common/globalVars'
66
import { ReqConfig, ResConfig } from '../types'
77
import { Config } from '@/common/types'
8+
import { isDockerEnvironment } from '@/common/utils/environment'
89

910
function isListenAllInterfaces(host: string | undefined): boolean {
1011
return !host || host === '0.0.0.0' || host === '::'
@@ -41,16 +42,19 @@ export function createConfigRoutes(ctx: Context): Router {
4142
// 获取网卡列表
4243
router.get('/network-interfaces', (req, res) => {
4344
try {
45+
const isDocker = isDockerEnvironment()
4446
const interfaces = networkInterfaces()
4547
const addresses: string[] = []
46-
for (const name in interfaces) {
47-
for (const iface of interfaces[name] || []) {
48-
if (iface.family === 'IPv4' && !iface.internal) {
49-
addresses.push(iface.address)
48+
if (!isDocker) {
49+
for (const name in interfaces) {
50+
for (const iface of interfaces[name] || []) {
51+
if (iface.family === 'IPv4' && !iface.internal) {
52+
addresses.push(iface.address)
53+
}
5054
}
5155
}
5256
}
53-
res.json({ success: true, data: addresses })
57+
res.json({ success: true, data: addresses, isDocker })
5458
} catch (e) {
5559
res.status(500).json({ success: false, message: '获取网卡列表失败', error: e })
5660
}

src/webui/FE/components/common/HostSelector.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ interface Option {
1313
}
1414

1515
let cachedNetworkInterfaces: string[] | null = null
16+
let cachedIsDocker: boolean = false
1617

1718
export const HostSelector: React.FC<HostSelectorProps> = ({ value, onChange }) => {
1819
const [networkInterfaces, setNetworkInterfaces] = useState<string[]>(cachedNetworkInterfaces || [])
20+
const [isDocker, setIsDocker] = useState(cachedIsDocker)
1921
const [isOpen, setIsOpen] = useState(false)
2022
const [isCustom, setIsCustom] = useState(false)
2123
const [customHost, setCustomHost] = useState('')
@@ -26,9 +28,16 @@ export const HostSelector: React.FC<HostSelectorProps> = ({ value, onChange }) =
2628
apiFetch<string[]>('/api/network-interfaces').then(res => {
2729
if (res.success) {
2830
cachedNetworkInterfaces = res.data
31+
cachedIsDocker = !!(res as any).isDocker
2932
setNetworkInterfaces(res.data)
33+
setIsDocker(cachedIsDocker)
34+
if (cachedIsDocker && value !== '') {
35+
onChange('')
36+
}
3037
}
3138
})
39+
} else if (isDocker && value !== '') {
40+
onChange('')
3241
}
3342
}, [])
3443

@@ -84,6 +93,16 @@ export const HostSelector: React.FC<HostSelectorProps> = ({ value, onChange }) =
8493
onChange(val)
8594
}
8695

96+
if (isDocker) {
97+
return (
98+
<div className='flex items-center gap-2'>
99+
<div className='input-field w-full text-left opacity-70 cursor-not-allowed'>
100+
全部 (0.0.0.0 和 ::)
101+
</div>
102+
</div>
103+
)
104+
}
105+
87106
return (
88107
<div className='flex items-center gap-2'>
89108
<div className='relative flex-1 z-[9999]' ref={dropdownRef}>

0 commit comments

Comments
 (0)