From 093af3a36f1ee087b4aa8b211ef4bb4e8a724696 Mon Sep 17 00:00:00 2001 From: Arnab-Afk Date: Mon, 8 Dec 2025 16:14:52 +0530 Subject: [PATCH] feat: Set up initial Docker Compose environment for client and server with Nginx, Express, MongoDB, and JWT/Google OAuth authentication. --- client/.env.example | 1 + client/Dockerfile | 3 +++ client/nginx.conf | 18 ++++++++++++++++++ docker-compose.yml | 10 +++++++--- server/.env.example | 6 ++++++ server/server.js | 2 +- 6 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 client/.env.example create mode 100644 client/nginx.conf create mode 100644 server/.env.example diff --git a/client/.env.example b/client/.env.example new file mode 100644 index 0000000..1209221 --- /dev/null +++ b/client/.env.example @@ -0,0 +1 @@ +REACT_APP_API_URL=http://localhost:8080/api diff --git a/client/Dockerfile b/client/Dockerfile index 3b39443..f74436b 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -7,12 +7,15 @@ COPY package*.json ./ RUN npm install COPY . . +ARG REACT_APP_API_URL +ENV REACT_APP_API_URL=$REACT_APP_API_URL RUN npm run build # Stage 2: Serve the application with Nginx FROM nginx:alpine COPY --from=build /app/build /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 80 diff --git a/client/nginx.conf b/client/nginx.conf new file mode 100644 index 0000000..24b23f0 --- /dev/null +++ b/client/nginx.conf @@ -0,0 +1,18 @@ +server { + listen 80; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } + + location /api { + proxy_pass http://server:8080; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } +} diff --git a/docker-compose.yml b/docker-compose.yml index 755773a..254aa15 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,18 +4,22 @@ services: server: build: ./server ports: - - "8080:8080" + - "10090:8080" environment: - mongoURI=mongodb://mongo:27017/appointment_to_examiner + - CORS_ORIGIN=http://localhost:10091 depends_on: - mongo networks: - app-network client: - build: ./client + build: + context: ./client + args: + - REACT_APP_API_URL=/api ports: - - "3000:80" + - "10091:80" depends_on: - server networks: diff --git a/server/.env.example b/server/.env.example new file mode 100644 index 0000000..6348bf9 --- /dev/null +++ b/server/.env.example @@ -0,0 +1,6 @@ +mongoURI=mongodb://localhost:27017/appointment_to_examiner +JWT_SECRET=your_jwt_secret +GOOGLE_CLIENT_ID=your_google_client_id +GOOGLE_CLIENT_SECRET=your_google_client_secret +GOOGLE_REFRESH_TOKEN=your_google_refresh_token +EMAIL_USERNAME=your_email@gmail.com diff --git a/server/server.js b/server/server.js index 516813d..255c464 100644 --- a/server/server.js +++ b/server/server.js @@ -35,7 +35,7 @@ const app = express(); const PORT = 8080; // Middleware -app.use(cors({ origin: "http://localhost:3000", credentials: true })); +app.use(cors({ origin: process.env.CORS_ORIGIN || "http://localhost:3000", credentials: true })); app.use(cookieparser()); app.use(express.json()); app.use(bodyParser.urlencoded({ extended: true }));