From b3f2cc97444576a9fdf26459ed14c6adc88c64cf Mon Sep 17 00:00:00 2001 From: djeck1432 Date: Wed, 2 Oct 2024 21:59:56 +0200 Subject: [PATCH] adjust nginx file --- frontend/Dockerfile | 26 ++++++++++---------------- spotnet.conf | 7 ++++++- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 3efc55b1..b52a022e 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -3,28 +3,22 @@ FROM node:20-alpine AS build WORKDIR /usr/src/app -# Copy package.json and package-lock.json to install dependencies -COPY package*.json ./ +WORKDIR /app -# Install dependencies -# Remove --legacy-peer-deps unless absolutely necessary -RUN npm ci --only=production +COPY . /app -# Copy the rest of the application source code -COPY . . +RUN yarn +#build the project for production +RUN yarn build -# Build the app -RUN npm run build - -# Stage 2: Serve the built app using nginx FROM nginx:alpine +# copy the build folder from react to the root of nginx (www) +COPY --from=build /app/build /usr/share/nginx/html +RUN rm /etc/nginx/conf.d/default.conf -# Copy the built files from the previous stage to the nginx container -COPY --from=build /usr/src/app/build /usr/share/nginx/html +COPY nginx/nginx.conf /etc/nginx/conf.d -# Expose the port Nginx will listen to EXPOSE 80 - -# Use CMD instead of ENTRYPOINT for more flexibility +# start nginx CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/spotnet.conf b/spotnet.conf index 405a7a92..0432c3ec 100644 --- a/spotnet.conf +++ b/spotnet.conf @@ -21,10 +21,15 @@ server { error_log /var/log/nginx/error.log; location / { - root /usr/share/nginx/html; + root /usr/share/nginx/html; + index index.html index.htm; try_files $uri $uri/ /index.html; } + location = /50x.html { + root /usr/share/nginx/html; + } + # Proxy requests to FastAPI backend API location /api/ { proxy_pass http://backend_app;