Merged Caddy into docker-compose and added edge CORS handling

This commit is contained in:
2026-02-10 21:34:54 +08:00
parent e83bb522a4
commit 36530eb2c5
2 changed files with 44 additions and 10 deletions

20
Caddyfile Normal file
View File

@@ -0,0 +1,20 @@
ai-gateway.ldex.dev {
# 1. Force CORS headers for every request
header {
Access-Control-Allow-Origin *
Access-Control-Allow-Methods "GET, POST, OPTIONS"
Access-Control-Allow-Headers "*"
Access-Control-Expose-Headers "*"
}
# 2. Immediately handle OPTIONS requests (the preflight)
@options {
method OPTIONS
}
handle @options {
respond "" 204
}
# 3. Proxy everything else to the app
reverse_proxy ai-gateway:8000
}

View File

@@ -1,20 +1,34 @@
services:
api:
ai-gateway:
build: .
container_name: ai-gateway
networks:
- caddy_network
#ports:
# - "8000:8000"
- ai_network
env_file:
- .env
restart: always
caddy:
image: caddy:latest
container_name: caddy
restart: always
ports:
- "80:80"
- "443:443"
- "443:443/udp"
networks:
- ai_network
volumes:
- .:/app
# Override command for development/auto-reload if needed
command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
- caddy_config:/config
depends_on:
- ai-gateway
networks:
caddy_network:
# Define the network at the bottom
external: true
ai_network:
driver: bridge
volumes:
caddy_data:
caddy_config: