From 8e0434c0e9bf85a83280e26441ae802b7d131a99 Mon Sep 17 00:00:00 2001 From: Saketh Surya Date: Mon, 16 Dec 2024 11:12:35 +0530 Subject: [PATCH] fix --- Frontend/Dockerfile | 13 ++++--------- Frontend/README.md | 8 -------- Frontend/config/nginx.conf | 24 ++++++++++++++++++++++++ Frontend/package.json | 3 ++- Frontend/src/App.jsx | 2 -- 5 files changed, 30 insertions(+), 20 deletions(-) delete mode 100644 Frontend/README.md create mode 100644 Frontend/config/nginx.conf diff --git a/Frontend/Dockerfile b/Frontend/Dockerfile index 1c5754a..0fa49d6 100644 --- a/Frontend/Dockerfile +++ b/Frontend/Dockerfile @@ -1,8 +1,8 @@ # Use the official Node.js 20 image -FROM node:18 as builder +FROM node:18-alphine AS builder # Set the working directory -WORKDIR /usr/src/app +WORKDIR /app # Copy package.json and package-lock.json COPY package*.json ./ @@ -15,17 +15,12 @@ COPY . . RUN npm run build -# Expose port FROM nginx:stable-alpine -# Copy built files from the builder stage -WORKDIR /usr/share/nginx/html +COPY --from=builder /app/dist /usr/share/nginx/html -RUN rm -rf * +COPY config/nginx.conf /etc/nginx/conf.d/default.conf -COPY --from=builder /usr/src/app/dist . - -# Expose port 80 and start nginx EXPOSE 80 ENTRYPOINT ["nginx", "-g", "daemon off;"] diff --git a/Frontend/README.md b/Frontend/README.md deleted file mode 100644 index f768e33..0000000 --- a/Frontend/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# React + Vite - -This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. - -Currently, two official plugins are available: - -- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh -- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh diff --git a/Frontend/config/nginx.conf b/Frontend/config/nginx.conf new file mode 100644 index 0000000..34bec51 --- /dev/null +++ b/Frontend/config/nginx.conf @@ -0,0 +1,24 @@ +server { + listen 80; + server_name localhost; + + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri /index.html; # SPA fallback + } + + location /assets/ { + expires 1y; + add_header Cache-Control "public"; + } + + error_page 404 /index.html; + + # Optional: Compression for better performance + gzip on; + gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; + gzip_proxied any; + gzip_min_length 256; +} diff --git a/Frontend/package.json b/Frontend/package.json index ebcf8cf..387c39a 100644 --- a/Frontend/package.json +++ b/Frontend/package.json @@ -7,7 +7,8 @@ "dev": "vite", "build": "vite build", "lint": "eslint .", - "preview": "vite preview" + "preview": "vite preview", + "serve": "vite preview" }, "dependencies": { "@emotion/react": "^11.13.5", diff --git a/Frontend/src/App.jsx b/Frontend/src/App.jsx index 3973049..f867a66 100644 --- a/Frontend/src/App.jsx +++ b/Frontend/src/App.jsx @@ -59,11 +59,9 @@ function App() { element={} /> } /> - } /> )} {!isLogin && } />} - {isLogin && } />}