Skip to content

Commit 67824d9

Browse files
committed
Update frontend Dockerfile for deployment
1 parent 9d5ca66 commit 67824d9

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

Frontend/Dockerfile

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
1-
# Use an official Node.js image as a base image
2-
FROM node:20 AS build
1+
# Step 1: Build the React app
2+
FROM node:18 AS builder
33

44
WORKDIR /app
55

6+
# Install dependencies
67
COPY package*.json ./
78
RUN npm install
89

10+
# Copy source files and build the app
911
COPY . .
10-
11-
# Build the React app
1212
RUN npm run build
13-
# Use a lightweight web server to serve static files
13+
14+
# Step 2: Serve with Nginx
1415
FROM nginx:alpine
15-
# Copy build files to NGINX's default public folder
16-
COPY --from=build /app/build /usr/share/nginx/html
17-
# Expose port 8080 for Cloud Run
18-
EXPOSE 8080
19-
# Start NGINX server
16+
17+
# Copy custom Nginx configuration
18+
COPY nginx.conf /etc/nginx/conf.d/default.conf
19+
20+
# Copy the build files to Nginx's web directory
21+
COPY --from=builder /app/build /usr/share/nginx/html
22+
23+
# Expose port 80
24+
EXPOSE 80
25+
26+
# Run Nginx
2027
CMD ["nginx", "-g", "daemon off;"]

Frontend/nginx.conf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
server {
2+
listen 80;
3+
server_name localhost;
4+
5+
# Serve the build directory as the root
6+
root /usr/share/nginx/html;
7+
index index.html;
8+
9+
# Redirect all routes to index.html for client-side routing
10+
location / {
11+
try_files $uri /index.html;
12+
}
13+
14+
# Serve static files directly
15+
location /static/ {
16+
expires 1y;
17+
add_header Cache-Control "public";
18+
}
19+
}

0 commit comments

Comments
 (0)