Skip to content

Commit

Permalink
Updade .env.example, .gitignore, and include nginx for load balancing
Browse files Browse the repository at this point in the history
  • Loading branch information
VitorCarvalho67 committed Jan 29, 2024
1 parent ba27a25 commit e7a96da
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DATABASE_URL="mysql://testuser:123pass@database:3306/biblioteca"
# JWT_ACCESS_SECRET=fghjdsklgh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
# Keep environment variables out of version control
.env
data
30 changes: 29 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
version: '3'

services:
server:
api01: &api
build: ./
ports:
- "3000:3000"
depends_on:
- database
deploy:
resources:
limits:
cpus: '0.15'
memory: '0.4GB'
command: sh -c "sleep 10 && npx prisma migrate deploy"
networks:
- API

api02:
<<: *api
ports:
- "3001:3000"

nginx: # Load Balancer
image: nginx:latest
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- api01
- api02
deploy:
resources:
limits:
cpus: '0.15'
memory: '0.5GB'
ports:
- "9999:9999"
networks:
- API

Expand Down
46 changes: 46 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
worker_processes auto;
worker_rlimit_nofile 500000;

events {
use epoll;
worker_connections 1024;
}

http {
access_log off;
error_log /dev/null emerg;

upstream api {
server api01:3000;
server api02:3001; # Alterei de localhost para o nome do serviço
keepalive 200;
}

server {
listen 9999;
location / {
proxy_buffering off;
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_set_header Connection "";

# Simple requests
if ($request_method ~* "(GET|POST)") {
add_header "Access-Control-Allow-Origin" *;
}

# Preflighted requests
if ($request_method = OPTIONS ) {
add_header "Access-Control-Allow-Origin" *;
add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, HEAD";
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
return 200;
}

proxy_http_version 1.1;
proxy_pass http://api;
}
}
}

0 comments on commit e7a96da

Please sign in to comment.