fix: enhance Traefik routing for API and web services in Docker Compose
All checks were successful
Build and Deploy Thoughts / build-and-deploy-local (push) Successful in 17s
All checks were successful
Build and Deploy Thoughts / build-and-deploy-local (push) Successful in 17s
This commit is contained in:
@@ -40,6 +40,19 @@ services:
|
|||||||
retries: 5
|
retries: 5
|
||||||
networks:
|
networks:
|
||||||
- internal
|
- internal
|
||||||
|
- traefik
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
# Create a router for the API
|
||||||
|
- "traefik.http.routers.thoughts-api.rule=Host(`thoughts.gabrielkaszewski.dev`) && PathPrefix(`/api`)"
|
||||||
|
- "traefik.http.routers.thoughts-api.entrypoints=web,websecure"
|
||||||
|
- "traefik.http.routers.thoughts-api.tls.certresolver=letsencrypt"
|
||||||
|
- "traefik.http.routers.thoughts-api.service=thoughts-api"
|
||||||
|
# Add a middleware to strip the /api prefix before sending to the backend
|
||||||
|
- "traefik.http.routers.thoughts-api.middlewares=strip-api-prefix"
|
||||||
|
- "traefik.http.middlewares.strip-api-prefix.stripprefix.prefixes=/api"
|
||||||
|
# Create a service for the API that points to the backend container's port
|
||||||
|
- "traefik.http.services.thoughts-api.loadbalancer.server.port=8000"
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
container_name: thoughts-frontend
|
container_name: thoughts-frontend
|
||||||
@@ -53,29 +66,43 @@ services:
|
|||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
environment:
|
environment:
|
||||||
- NEXT_PUBLIC_SERVER_SIDE_API_URL=http://proxy/api
|
- NEXT_PUBLIC_SERVER_SIDE_API_URL=http://backend:8000
|
||||||
networks:
|
- PORT=3000
|
||||||
- internal
|
- HOSTNAME=0.0.0.0
|
||||||
|
|
||||||
proxy:
|
|
||||||
container_name: thoughts-proxy
|
|
||||||
image: custom-proxy:latest
|
|
||||||
restart: unless-stopped
|
|
||||||
depends_on:
|
|
||||||
frontend:
|
|
||||||
condition: service_healthy
|
|
||||||
backend:
|
|
||||||
condition: service_healthy
|
|
||||||
networks:
|
networks:
|
||||||
- internal
|
- internal
|
||||||
- traefik
|
- traefik
|
||||||
labels:
|
labels:
|
||||||
- "traefik.enable=true"
|
- "traefik.enable=true"
|
||||||
- "traefik.http.routers.thoughts.rule=Host(`thoughts.gabrielkaszewski.dev`)"
|
# Create a router for the main web traffic
|
||||||
- "traefik.http.routers.thoughts.entrypoints=web,websecure"
|
- "traefik.http.routers.thoughts-web.rule=Host(`thoughts.gabrielkaszewski.dev`)"
|
||||||
- "traefik.http.routers.thoughts.tls.certresolver=letsencrypt"
|
- "traefik.http.routers.thoughts-web.entrypoints=web,websecure"
|
||||||
- "traefik.http.routers.thoughts.service=thoughts"
|
- "traefik.http.routers.thoughts-web.tls.certresolver=letsencrypt"
|
||||||
- "traefik.http.services.thoughts.loadbalancer.server.port=80"
|
- "traefik.http.routers.thoughts-web.service=thoughts-web"
|
||||||
|
# Give this router a lower priority so the more specific /api route is matched first
|
||||||
|
- "traefik.http.routers.thoughts-web.priority=1"
|
||||||
|
# Create a service for the web that points to the frontend container's port
|
||||||
|
- "traefik.http.services.thoughts-web.loadbalancer.server.port=3000"
|
||||||
|
|
||||||
|
# proxy:
|
||||||
|
# container_name: thoughts-proxy
|
||||||
|
# image: custom-proxy:latest
|
||||||
|
# restart: unless-stopped
|
||||||
|
# depends_on:
|
||||||
|
# frontend:
|
||||||
|
# condition: service_healthy
|
||||||
|
# backend:
|
||||||
|
# condition: service_healthy
|
||||||
|
# networks:
|
||||||
|
# - internal
|
||||||
|
# - traefik
|
||||||
|
# labels:
|
||||||
|
# - "traefik.enable=true"
|
||||||
|
# - "traefik.http.routers.thoughts.rule=Host(`thoughts.gabrielkaszewski.dev`)"
|
||||||
|
# - "traefik.http.routers.thoughts.entrypoints=web,websecure"
|
||||||
|
# - "traefik.http.routers.thoughts.tls.certresolver=letsencrypt"
|
||||||
|
# - "traefik.http.routers.thoughts.service=thoughts"
|
||||||
|
# - "traefik.http.services.thoughts.loadbalancer.server.port=80"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
|
Reference in New Issue
Block a user