From cfb3a4acb6e6798a97c4f1961ea5eba3f139b959 Mon Sep 17 00:00:00 2001 From: Luke Gustafson Date: Wed, 27 Nov 2024 03:59:16 +0000 Subject: [PATCH] Commit --- docker/Dockerfile | 10 +++++---- docker/nginx.conf | 55 ++++++++++++++++++++++++----------------------- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 7191fc5a..b68e9d72 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -13,15 +13,17 @@ COPY backend/package*.json ./ RUN npm install COPY backend/ . -# Production image using nginx:alpine FROM nginx:alpine + +RUN apk add --no-cache nodejs npm COPY docker/nginx.conf /etc/nginx/nginx.conf COPY --from=frontend-build /app/frontend/dist /usr/share/nginx/html COPY --from=backend-build /backend /backend COPY --from=backend-build /backend/entrypoint.sh /backend/entrypoint.sh -# Make entrypoint.sh executable RUN chmod +x /backend/entrypoint.sh -# Use entrypoint script to start backend and frontend servers -ENTRYPOINT ["/backend/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/backend/entrypoint.sh"] + +EXPOSE 80 +EXPOSE 3001 \ No newline at end of file diff --git a/docker/nginx.conf b/docker/nginx.conf index ca7e4026..56070bdb 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -1,31 +1,32 @@ -server { - listen 80; +http { + server { + listen 80; + server_name localhost; - server_name localhost; - - # Serve the React app - root /usr/share/nginx/html; - index index.html; - - # Frontend routes (SPA) - location / { - try_files $uri /index.html; - } - - # API routes (proxy to backend) - location /api/ { - proxy_pass http://127.0.0.1:3001; # Forward API requests to backend - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header Host $host; - proxy_redirect off; # Disable automatic redirects by the backend (if any) - } - - # Optional: Custom error handling - error_page 404 /404.html; - error_page 500 502 503 504 /50x.html; - location = /50x.html { + # Serve the React app root /usr/share/nginx/html; + index index.html; + + # Frontend routes (SPA) + location / { + try_files $uri /index.html; + } + + # API routes (proxy to backend) + location /api/ { + proxy_pass http://127.0.0.1:3001; # Forward API requests to backend + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_redirect off; # Disable automatic redirects by the backend (if any) + } + + # Optional: Custom error handling + error_page 404 /404.html; + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } } } \ No newline at end of file