Commit
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#!/bin/sh
|
||||
# Start the backend server in the background
|
||||
|
||||
# Start the backend server
|
||||
node /backend/server.js &
|
||||
# Start Nginx in the foreground
|
||||
nginx -g "daemon off;"
|
||||
|
||||
# Start nginx in the foreground
|
||||
nginx -g 'daemon off;'
|
||||
@@ -1,40 +1,27 @@
|
||||
# Build frontend
|
||||
FROM ubuntu:20.04 AS frontend-build
|
||||
FROM node:18-alpine AS frontend-build
|
||||
WORKDIR /app
|
||||
# Install Node.js
|
||||
RUN apt-get update && apt-get install -y curl && \
|
||||
curl -sL https://deb.nodesource.com/setup_18.x | bash - && \
|
||||
apt-get install -y nodejs && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
COPY frontend/package*.json ./frontend/
|
||||
RUN npm --prefix frontend install
|
||||
COPY frontend/ ./frontend/
|
||||
RUN npm --prefix frontend run build
|
||||
|
||||
# Build backend
|
||||
FROM ubuntu:20.04 AS backend-build
|
||||
FROM node:18-alpine AS backend-build
|
||||
WORKDIR /backend
|
||||
# Install Node.js
|
||||
RUN apt-get update && apt-get install -y curl && \
|
||||
curl -sL https://deb.nodesource.com/setup_18.x | bash - && \
|
||||
apt-get install -y nodejs && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
COPY backend/package*.json ./
|
||||
RUN npm install
|
||||
COPY backend/ .
|
||||
|
||||
# Production image
|
||||
FROM ubuntu:20.04
|
||||
# Install Node.js and Nginx
|
||||
RUN apt-get update && apt-get install -y curl nginx && \
|
||||
curl -sL https://deb.nodesource.com/setup_18.x | bash - && \
|
||||
apt-get install -y nodejs && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
# Copy frontend and backend
|
||||
# Production image using nginx:alpine
|
||||
FROM nginx:alpine
|
||||
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 entrypoint script
|
||||
COPY backend/entrypoint.sh /backend/entrypoint.sh
|
||||
COPY --from=backend-build /backend/entrypoint.sh /backend/entrypoint.sh
|
||||
|
||||
# Make entrypoint.sh executable
|
||||
RUN chmod +x /backend/entrypoint.sh
|
||||
# Start backend and frontend servers using entrypoint script
|
||||
CMD ["/backend/entrypoint.sh"]
|
||||
|
||||
# Use entrypoint script to start backend and frontend servers
|
||||
ENTRYPOINT ["/backend/entrypoint.sh"]
|
||||
@@ -7,7 +7,7 @@ server {
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Frontend routes
|
||||
# Frontend routes (SPA)
|
||||
location / {
|
||||
try_files $uri /index.html;
|
||||
}
|
||||
@@ -19,5 +19,13 @@ server {
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user