Nomio4640 Claude Sonnet 4.6 commited on
Commit
e11aca2
·
1 Parent(s): c28162d

fix: wait for FastAPI/Next.js health before starting nginx

Browse files

- Replace fixed sleep 5 with health-check loops (up to 120s for FastAPI,
60s for Next.js) so nginx only starts proxying once backends are ready
- Fix NEXT_PUBLIC_API_URL in Dockerfile to /api (relative) instead of
hardcoded localhost:8000

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (2) hide show
  1. Dockerfile +2 -1
  2. start.sh +18 -1
Dockerfile CHANGED
@@ -4,7 +4,8 @@ WORKDIR /app/frontend
4
  COPY frontend/package*.json ./
5
  RUN npm ci
6
  COPY frontend/ ./
7
- ENV NEXT_PUBLIC_API_URL=http://localhost:8000
 
8
  RUN npm run build
9
 
10
  FROM python:3.11-slim
 
4
  COPY frontend/package*.json ./
5
  RUN npm ci
6
  COPY frontend/ ./
7
+ #ENV NEXT_PUBLIC_API_URL=http://localhost:8000
8
+ ENV NEXT_PUBLIC_API_URL=/api
9
  RUN npm run build
10
 
11
  FROM python:3.11-slim
start.sh CHANGED
@@ -19,7 +19,24 @@ npm run start -- --port 3000 &
19
  NEXTJS_PID=$!
20
  echo "Next.js started (PID $NEXTJS_PID)"
21
 
22
- sleep 5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  nginx -g "daemon off;" &
24
 
25
  NGINX_PID=$!
 
19
  NEXTJS_PID=$!
20
  echo "Next.js started (PID $NEXTJS_PID)"
21
 
22
+ echo "Waiting for FastAPI to be ready..."
23
+ for i in $(seq 1 120); do
24
+ if curl -sf http://localhost:8000/ > /dev/null 2>&1; then
25
+ echo "FastAPI is ready (${i}s)"
26
+ break
27
+ fi
28
+ sleep 1
29
+ done
30
+
31
+ echo "Waiting for Next.js to be ready..."
32
+ for i in $(seq 1 60); do
33
+ if curl -sf http://localhost:3000/ > /dev/null 2>&1; then
34
+ echo "Next.js is ready (${i}s)"
35
+ break
36
+ fi
37
+ sleep 1
38
+ done
39
+
40
  nginx -g "daemon off;" &
41
 
42
  NGINX_PID=$!