Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# ADD DOCKERFILE CONTENTS HERE
FROM node:18-alpine

WORKDIR /app


COPY package*.json ./
RUN npm install


COPY . .


EXPOSE 8080

CMD ["node", "src/index.js"]
45 changes: 44 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
# ADD DOCKER-COMPOSE CONTENT HERE
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:

65 changes: 64 additions & 1 deletion nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1 +1,64 @@
# ADD NGINX CONFIGS HERE
# 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;
}
}
}