fix: 修复前端访问错误
This commit is contained in:
@@ -22,6 +22,18 @@ services:
|
||||
context: ./backend
|
||||
container_name: exam-helper-backend
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test:
|
||||
[
|
||||
"CMD",
|
||||
"python",
|
||||
"-c",
|
||||
"import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health', timeout=3).read()",
|
||||
]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 12
|
||||
start_period: 25s
|
||||
# AI 相关变量优先从 .env.example 注入;若存在 .env 则覆盖同名项(见 Compose env_file 顺序)
|
||||
env_file:
|
||||
- .env.example
|
||||
@@ -46,7 +58,8 @@ services:
|
||||
container_name: exam-helper-frontend
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- backend
|
||||
backend:
|
||||
condition: service_healthy
|
||||
ports:
|
||||
- "127.0.0.1:8173:80"
|
||||
|
||||
|
||||
7
frontend/.dockerignore
Normal file
7
frontend/.dockerignore
Normal file
@@ -0,0 +1,7 @@
|
||||
node_modules
|
||||
dist
|
||||
.git
|
||||
.gitignore
|
||||
*.md
|
||||
.DS_Store
|
||||
npm-debug.log*
|
||||
@@ -9,7 +9,9 @@ COPY package.json /app/package.json
|
||||
RUN npm config set registry https://registry.npmmirror.com && npm install
|
||||
|
||||
COPY . /app
|
||||
RUN npm run build
|
||||
RUN npm run build \
|
||||
&& test -f /app/dist/index.html \
|
||||
&& ls -la /app/dist
|
||||
|
||||
FROM nginx:1.27-alpine
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||||
|
||||
22
start.sh
22
start.sh
@@ -18,8 +18,24 @@ else
|
||||
echo "==> AI 配置来自 .env.example(请填写 QWEN_API_KEY;亦可复制为 .env 再填写)"
|
||||
fi
|
||||
|
||||
echo "==> 健康检查(端口与 docker-compose.yml 一致:后端 8866,前端 Nginx 8173)"
|
||||
echo "backend: $(curl -sf http://localhost:8866/health || echo 'unreachable')"
|
||||
echo "frontend (nginx): $(curl -sf http://localhost:8173/health || echo 'unreachable')"
|
||||
wait_http() {
|
||||
local url=$1
|
||||
local label=$2
|
||||
local i=0
|
||||
while [[ $i -lt 45 ]]; do
|
||||
if curl -sf "$url" >/dev/null 2>&1; then
|
||||
echo "${label}: ok"
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
i=$((i + 1))
|
||||
done
|
||||
echo "${label}: unreachable(请确认容器已就绪,或执行: curl -v ${url})"
|
||||
return 1
|
||||
}
|
||||
|
||||
echo "==> 健康检查(后端 8866,前端 Nginx 8173;最多等待约 45s)"
|
||||
wait_http "http://localhost:8866/health" "backend" || true
|
||||
wait_http "http://localhost:8173/health" "frontend (nginx)" || true
|
||||
|
||||
echo "==> 启动完成"
|
||||
|
||||
Reference in New Issue
Block a user