diff --git a/Dockerfile b/Dockerfile index b3de2962661430da48e87ad70cda92966ad0d2b4..b7de8226be9638a69c56330e8eb4cc7c1aca61f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# Use the official Node.js image as the base image +# official Node.js image as the base image FROM node:18 # Set the working directory inside the container @@ -7,13 +7,13 @@ WORKDIR /app # Copy package.json and package-lock.json to the container COPY package*.json ./ -# Install dependencies +# Install dependencies from packages RUN npm install # Copy the rest of the application code to the container COPY . . -# Expose the application port +# application port EXPOSE 3000 # Start the application diff --git a/docker-compose.yml b/docker-compose.yml index a5aab92c97e3eaeb3df9f3398f94e0135f76b5a9..4c50541db0bdf9686972028d0a7ecb64ae006252 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,24 @@ services: - app: + app1: build: context: . dockerfile: Dockerfile ports: - - "3000:3000" # Expose the app on port 3000 + - "3001:3000" # Map container port 3000 to host port 3001 environment: + - PORT=3000 + - MONGO_URL=mongodb://db:27017/todo-app # MongoDB connection string + depends_on: + - db + + app2: + build: + context: . + dockerfile: Dockerfile + ports: + - "3002:3000" # Map container port 3000 to host port 3002 + environment: + - PORT=3000 - MONGO_URL=mongodb://db:27017/todo-app # MongoDB connection string depends_on: - db @@ -14,9 +27,9 @@ services: image: mongo:6.0 container_name: mongodb ports: - - "27017:27017" # Expose MongoDB on port 27017 + - "27017:27017" volumes: - - mongo-data:/data/db # Persist MongoDB data + - mongo-data:/data/db # MongoDB data Volume volumes: mongo-data: \ No newline at end of file diff --git a/public/index.html b/public/index.html index ea939c46b0bc5a73878b0ac792ebd1b9152c2c76..d7a502f82c37f938e2ebab051cda9d2d169a4fdd 100644 --- a/public/index.html +++ b/public/index.html @@ -15,7 +15,7 @@ <script> // Base URL for the backend API - const API_URL = 'http://localhost:3000/todos'; + const API_URL = `${window.location.origin}/todos`; let showAll = false; // State to toggle visibility of completed TODOs // Fetch and display TODO items from the backend diff --git a/server.js b/server.js index 28c9107f830db942c36d6054ca89126fb55b255e..c465d46c89c9b576356855d8020fbd6148c4bdc3 100644 --- a/server.js +++ b/server.js @@ -6,7 +6,7 @@ const path = require('path'); // Import path module for serving static files // Initialize Express app const app = express(); -const PORT = 3000; // Define the port the server will run on +const PORT = process.env.PORT || 3000; // Define the port the server will run on // Middleware setup app.use(express.json()); // Parse incoming JSON requests