diff --git a/deployment/app-pgsql/docker-compose.yaml b/deployment/app-pgsql/docker-compose.yaml index 2f62d43..dd16e38 100644 --- a/deployment/app-pgsql/docker-compose.yaml +++ b/deployment/app-pgsql/docker-compose.yaml @@ -138,6 +138,34 @@ services: - gqueue - observability + nginx: + image: nginx:alpine + ports: + - 8080:80 + volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro + depends_on: + backoffice: + condition: service_started + pubsub: + condition: service_started + task: + condition: service_started + networks: + - app-network + deploy: + resources: + limits: + cpus: "0.5" + memory: 128M + reservations: + cpus: "0.1" + memory: 64M + profiles: + - complete + - gqueue + - observability + redis: image: redis:latest ports: diff --git a/deployment/app-pgsql/nginx/nginx.conf b/deployment/app-pgsql/nginx/nginx.conf new file mode 100644 index 0000000..b5bdba4 --- /dev/null +++ b/deployment/app-pgsql/nginx/nginx.conf @@ -0,0 +1,58 @@ +worker_processes auto; +error_log /var/log/nginx/error.log warn; +pid /tmp/nginx.pid; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + access_log /var/log/nginx/access.log main; + + sendfile on; + keepalive_timeout 65; + types_hash_max_size 2048; + + limit_req_zone $binary_remote_addr zone=api:10m rate=2000r/s; + + server { + listen 80; + server_name _; + client_max_body_size 1m; + + # Common proxy settings (inherited by locations); path is passed through unchanged + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_connect_timeout 60s; + proxy_send_timeout 60s; + proxy_read_timeout 60s; + + # Prefix routing: most specific first. No path rewrite — backend receives full URI. + location /api/v1/pubsub { + limit_req zone=api burst=1000 nodelay; + proxy_pass http://pubsub:8082; + } + + location /api/v1/task { + limit_req zone=api burst=1000 nodelay; + proxy_pass http://task:8083; + } + + location /api/v1/ { + limit_req zone=api burst=1000 nodelay; + proxy_pass http://backoffice:8081; + } + + location / { + return 404; + } + } +} diff --git a/example/example.md b/example/example.md index 961c704..03b90ac 100644 --- a/example/example.md +++ b/example/example.md @@ -1,7 +1,7 @@ ### Example create or update event curl -X PATCH \ - http://localhost:8081/api/v1/event/consumer \ + http://localhost:8080/api/v1/event/consumer \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" \ @@ -11,11 +11,11 @@ curl -X PATCH \ curl -X GET \ -H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" \ - http://localhost:8081/api/v1/events/payment.charged1 | jq + http://localhost:8080/api/v1/events/payment.charged1 | jq curl -X GET \ -H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" \ - http://localhost:8081/api/v1/events + http://localhost:8080/api/v1/events curl -X GET \ -H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" \ @@ -24,13 +24,13 @@ curl -X GET \ ### Publisher data curl -X POST \ - http://localhost:8082/api/v1/pubsub \ + http://localhost:8080/api/v1/pubsub \ -H "Content-Type: application/json" \ -H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" \ -d @example/pubsub_event_payload.json curl -X POST \ - http://localhost:8083/api/v1/task \ + http://localhost:8080/api/v1/task \ -H "Content-Type: application/json" \ -H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" \ -d @example/task_event_payload.json diff --git a/example/simulation/multiples_producer_pubsub.sh b/example/simulation/multiples_producer_pubsub.sh index 502179a..5b89b67 100644 --- a/example/simulation/multiples_producer_pubsub.sh +++ b/example/simulation/multiples_producer_pubsub.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -URL="http://localhost:8082/api/v1/pubsub" +URL="http://localhost:8080/api/v1/pubsub" AUTH="Basic YWRtaW46cGFzc3dvcmQ=" DATA_FILE="example/pubsub_event_payload.json" diff --git a/example/simulation/multiples_producer_task.sh b/example/simulation/multiples_producer_task.sh index f3c45aa..1ff1333 100644 --- a/example/simulation/multiples_producer_task.sh +++ b/example/simulation/multiples_producer_task.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -URL="http://localhost:8083/api/v1/task" +URL="http://localhost:8080/api/v1/task" AUTH="Basic YWRtaW46cGFzc3dvcmQ=" DATA_FILE="example/task_event_payload.json"