-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from moheladwy/SolveCORS
fixed the bug in the cors
- Loading branch information
Showing
3 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
services: | ||
cache: | ||
image: redis:alpine | ||
container_name: todo-redis-cache | ||
networks: | ||
- todo-network | ||
ports: | ||
- "6379:6379" | ||
volumes: | ||
- redis-data:/data | ||
healthcheck: | ||
test: ["CMD", "redis-cli", "ping"] | ||
interval: 10s | ||
timeout: 10s | ||
retries: 3 | ||
labels: | ||
- "com.centurylinklabs.watchtower.enable=true" | ||
|
||
api: | ||
image: only1adwy/todo-api:latest | ||
environment: | ||
- ASPNETCORE_ENVIRONMENT=Production | ||
deploy: | ||
mode: replicated | ||
replicas: 2 | ||
update_config: | ||
parallelism: 1 | ||
restart_policy: | ||
condition: on-failure | ||
resources: | ||
limits: | ||
cpus: "1" | ||
memory: 1G | ||
reservations: | ||
cpus: "0.25" | ||
memory: 125M | ||
depends_on: | ||
- cache | ||
networks: | ||
- todo-network | ||
command: | ||
- "sh -c dotnet Todo.Api.dll ef database update && dotnet Todo.Api.dll" | ||
labels: | ||
- "com.centurylinklabs.watchtower.enable=true" | ||
|
||
nginx: | ||
image: nginx:alpine | ||
container_name: todo-reverse-proxy | ||
ports: | ||
- "8070:8070" | ||
volumes: | ||
- ./conf.d:/etc/nginx/conf.d | ||
- /var/run/docker.sock:/tmp/docker.sock:ro | ||
depends_on: | ||
- cache | ||
- api | ||
networks: | ||
- todo-network | ||
labels: | ||
- "com.centurylinklabs.watchtower.enable=true" | ||
|
||
volumes: | ||
redis-data: | ||
name: redis-data | ||
|
||
networks: | ||
todo-network: | ||
driver: bridge | ||
name: todo-network |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,39 @@ | ||
upstream api_backend { | ||
server api:8080; # Docker will automatically load balance between replicas | ||
keepalive 32; # Keep connections alive | ||
} | ||
|
||
# API Server | ||
server { | ||
listen 80; | ||
listen 8070; | ||
server_name api-todo.aladawy.duckdns.org; | ||
|
||
# Compression settings | ||
gzip on; | ||
gzip_types text/plain application/json; | ||
|
||
location / { | ||
proxy_pass http://todo-api:8070; | ||
} | ||
proxy_pass http://api_backend/; | ||
# Add CORS headers | ||
add_header 'Access-Control-Allow-Origin' 'https://tasker-aladawy.netlify.app' always; | ||
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always; | ||
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type' always; | ||
add_header 'Access-Control-Allow-Credentials' 'true' always; | ||
|
||
# Handle OPTIONS method | ||
if ($request_method = 'OPTIONS') { | ||
add_header 'Access-Control-Allow-Origin' 'https://tasker-aladawy.netlify.app' always; | ||
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always; | ||
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type' always; | ||
add_header 'Access-Control-Allow-Credentials' 'true' always; | ||
add_header 'Content-Type' 'text/plain charset=UTF-8'; | ||
add_header 'Content-Length' 0; | ||
return 204; | ||
} | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters