Skip to content

Commit 1253c1b

Browse files
authored
Merge pull request #6 from NicholasGoh/feat/nginx-reverse-proxy
Feat/nginx reverse proxy
2 parents f52a633 + 60516b0 commit 1253c1b

File tree

5 files changed

+64
-5
lines changed

5 files changed

+64
-5
lines changed

backend/api/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ COPY ./envs/backend.env /opt/.env
88
COPY ./backend/api /app/api
99
COPY ./backend/shared_mcp /app/shared_mcp
1010
ENV PYTHONPATH /app:$PYTHONPATH
11-
ENTRYPOINT ["uv", "run", "fastapi", "run", "api/main.py"]
11+
ENTRYPOINT ["uv", "run", "fastapi", "run", "api/main.py", "--root-path=/api"]

backend/mcp/Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ WORKDIR /app
44
COPY ./backend/mcp/uv.lock ./backend/mcp/pyproject.toml .
55
RUN uv sync --frozen && rm ./uv.lock ./pyproject.toml
66
RUN apt-get update && apt-get install -y --no-install-recommends \
7-
curl && \
8-
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
9-
apt-get install -y --no-install-recommends nodejs
7+
curl
108
COPY ./backend/mcp ./mcp
119
COPY ./backend/shared_mcp ./shared_mcp
1210
ENV PYTHONPATH /app:$PYTHONPATH
11+
ENV PATH /app:$PATH
1312
ENTRYPOINT ["uv", "run", "mcp/main.py"]

compose-dev.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
build:
55
context: .
66
dockerfile: ./backend/api/Dockerfile
7-
entrypoint: bash -c "uv run fastapi run api/main.py --reload"
7+
entrypoint: uv run fastapi run api/main.py --root-path=/api --reload
88
env_file:
99
- ./envs/shared_mcp.env
1010
ports:
@@ -21,6 +21,15 @@ services:
2121
dockerfile: ./backend/mcp/Dockerfile
2222
env_file:
2323
- ./envs/shared_mcp.env
24+
ports:
25+
- 8050:8050
2426
volumes:
2527
- ./backend/mcp:/app/mcp
2628
- ./backend/shared_mcp:/app/shared_mcp
29+
30+
nginx:
31+
image: nginx:1.26.3-alpine
32+
ports:
33+
- 80:80
34+
volumes:
35+
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf

compose.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,19 @@ services:
1515
env_file:
1616
- ./envs/shared_mcp.env
1717
restart: unless-stopped
18+
19+
nginx:
20+
image: nginx:1.26.3-alpine
21+
ports:
22+
- 80:80
23+
volumes:
24+
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
25+
restart: unless-stopped
26+
depends_on:
27+
api:
28+
condition: service_healthy
29+
healthcheck:
30+
test: curl -f http://localhost/docs
31+
interval: 30s
32+
timeout: 10s
33+
retries: 3

nginx/nginx.conf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
upstream api {
2+
server api:8000;
3+
}
4+
5+
server {
6+
listen 80;
7+
8+
location / {
9+
return 301 /api/docs;
10+
}
11+
12+
location /api/ {
13+
add_header Access-Control-Allow-Origin "*";
14+
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS, HEAD";
15+
add_header Access-Control-Allow-Headers "content-type";
16+
17+
proxy_set_header Cache-Control 'no-cache';
18+
proxy_set_header Content-Type $http_content_type;
19+
proxy_set_header X-Accel-Buffering 'no';
20+
21+
proxy_http_version 1.1;
22+
proxy_set_header Connection "";
23+
proxy_set_header Upgrade $http_upgrade;
24+
proxy_set_header Host $host;
25+
26+
proxy_buffering off;
27+
proxy_redirect off;
28+
proxy_pass http://api/;
29+
}
30+
31+
location /api/docs {
32+
proxy_redirect off;
33+
proxy_pass http://api/docs;
34+
}
35+
}

0 commit comments

Comments
 (0)