-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathstart-network.sh
More file actions
executable file
·57 lines (50 loc) · 1.59 KB
/
start-network.sh
File metadata and controls
executable file
·57 lines (50 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# 获取所有非本地 IPv4 地址
get_local_ips() {
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}'
else
# Linux
hostname -I | awk '{for(i=1;i<=NF;i++) if($i != "127.0.0.1") print $i}'
fi
}
# 获取网络接口名称
get_interface_name() {
if [[ "$OSTYPE" == "darwin"* ]]; then
ifconfig | grep -B 1 "inet " | grep -v 127.0.0.1 | grep "^[a-z]" | awk '{print $1}' | tr -d ':'
else
ip route get 1 | awk '{print $5; exit}'
fi
}
PORT=${PORT:-3000}
IPS=$(get_local_ips)
INTERFACES=$(get_interface_name)
echo ''
echo '============================================================'
echo '🚀 Docusaurus 开发服务器已启动'
echo '============================================================'
echo ''
echo '✅ 本地访问:'
echo ''
echo " ➜ http://localhost:$PORT"
echo " ➜ http://127.0.0.1:$PORT"
echo ''
if [ -n "$IPS" ]; then
echo '📱 局域网访问 (同一 WiFi 下的设备可访问):'
echo ''
i=1
echo "$IPS" | while read -r ip; do
if [ -n "$ip" ]; then
echo " ➜ http://$ip:$PORT"
fi
i=$((i + 1))
done
echo ''
fi
echo '────────────────────────────────────────────────────────────'
echo '💡 提示: 按 Ctrl+C 停止服务器'
echo '============================================================'
echo ''
# 启动 Docusaurus
npx docusaurus start --host 0.0.0.0 --port "$PORT"