打磨细节
This commit is contained in:
36
scripts/dev.sh
Normal file
36
scripts/dev.sh
Normal file
@@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 尝试的端口列表
|
||||
PORTS=(3002 3003 3004 3005 3006)
|
||||
|
||||
# 检查端口是否被占用
|
||||
check_port() {
|
||||
local port=$1
|
||||
if nc -z localhost $port 2>/dev/null || curl -s http://localhost:$port >/dev/null 2>&1; then
|
||||
return 1 # 端口被占用
|
||||
else
|
||||
return 0 # 端口可用
|
||||
fi
|
||||
}
|
||||
|
||||
# 查找可用端口
|
||||
find_available_port() {
|
||||
for port in "${PORTS[@]}"; do
|
||||
if check_port $port; then
|
||||
echo $port
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
# 如果预定义端口都被占用,随机选择一个
|
||||
echo $((3000 + RANDOM % 1000))
|
||||
return 0
|
||||
}
|
||||
|
||||
# 查找可用端口
|
||||
AVAILABLE_PORT=$(find_available_port)
|
||||
|
||||
echo "🚀 Starting dev server on port $AVAILABLE_PORT..."
|
||||
|
||||
# 启动开发服务器
|
||||
npx next dev -H 0.0.0.0 -p $AVAILABLE_PORT
|
||||
Reference in New Issue
Block a user