File tree Expand file tree Collapse file tree 2 files changed +36
-10
lines changed Expand file tree Collapse file tree 2 files changed +36
-10
lines changed Original file line number Diff line number Diff line change 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
3
3
4
4
WORKDIR /app
5
5
6
+ # Install dependencies
6
7
COPY package*.json ./
7
8
RUN npm install
8
9
10
+ # Copy source files and build the app
9
11
COPY . .
10
-
11
- # Build the React app
12
12
RUN npm run build
13
- # Use a lightweight web server to serve static files
13
+
14
+ # Step 2: Serve with Nginx
14
15
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
20
27
CMD ["nginx" , "-g" , "daemon off;" ]
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments