diff --git a/backend/Dockerfile b/backend/Dockerfile index 3feaa5b..775f466 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1 +1,15 @@ -# ADD DOCKERFILE CONTENTS HERE \ No newline at end of file +FROM node:18-alpine + +WORKDIR /app + + +COPY package*.json ./ +RUN npm install + + +COPY . . + + +EXPOSE 8080 + +CMD ["node", "src/index.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index db39ad0..e3d27ec 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1 +1,44 @@ -# ADD DOCKER-COMPOSE CONTENT HERE \ No newline at end of file +version: '3.9' + +services: + nodeapp: + build: ./backend + container_name: nodeapp + ports: + - "3000:8080" + environment: + - REDIS_HOST=redis + - REDIS_PORT=6379 + - MONGODB_URI=mongodb://mongo:27017/mydb + - NODE_ENV=development + depends_on: + - redis + - mongo + + redis: + image: redis:7 + container_name: redis + ports: + - "6379:6379" + volumes: + - redis-data:/data + restart: unless-stopped + + mongo: + image: mongo:7 + container_name: mongo + ports: + - "27017:27017" + + nginx: + image: nginx:latest + container_name: nginx + ports: + - "1234:80" + volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro + + +volumes: + redis-data: + diff --git a/nginx/nginx.conf b/nginx/nginx.conf index e4efe51..c7e8b0a 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1 +1,64 @@ -# ADD NGINX CONFIGS HERE \ No newline at end of file +# nginx.conf +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log warn; +pid /var/run/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; + server_tokens off; + + upstream node_app { + server nodeapp:3000; + } + + server { + listen 80; + server_name localhost; + + # Health check endpoint + location /health { + proxy_pass http://node_app/health; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + + # API routes + location /api/ { + proxy_pass http://node_app$request_uri; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + + # Default fallback + location / { + proxy_pass http://node_app; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + } +}