Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ignore dependencies, git, and sensitive files
node_modules
npm-debug.log
.git
.gitignore

# Ignore session and upload data
sessions/
uploads/
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use the official Node.js 20 Alpine image as a base
FROM node:20-alpine

# Set the working directory in the container
WORKDIR /usr/src/app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application source code
COPY . .

# Expose the port the app runs on
EXPOSE 3000

# Command to run the application
CMD [ "npm", "start" ]
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,71 @@ npm start

---

## 🐳 Running with Docker

You can also run this application using Docker and Docker Compose for a more isolated and reproducible setup.

### **1. Using Docker Compose (Recommended)**

This is the easiest way to get started.

1. **Create an Environment File**:
Create a `.env` file in the root of the project. This file will be used by Docker Compose to set the environment variables inside the container.

```
# .env

# The master key to protect the server
MASTER_API_KEY=yoursecretkey

# The port to run the server on (optional, defaults to 3000)
PORT=3000
```

2. **Build and Run the Container**:
Run the following command to build the Docker image and start the container in the background:

```bash
docker compose up --build -d
```

The server will now be running on the port you specified (or the default, 3000).

3. **To Stop the Server**:
```bash
docker compose down
```

### **2. Using Docker (Manual)**

If you prefer not to use Docker Compose, you can build and run the container manually.

1. **Build the Docker Image**:
```bash
docker build -t whatsapp-api .
```

2. **Run the Docker Container**:
You must pass the `MASTER_API_KEY` and map the port. You also need to create and mount volumes to persist the `sessions` and `uploads` data.

```bash
docker run -d \
-p 3000:3000 \
-e MASTER_API_KEY="yoursecretkey" \
-e PORT="3000" \
--name whatsapp-api-container \
-v whatsapp_sessions:/usr/src/app/sessions \
-v whatsapp_uploads:/usr/src/app/uploads \
whatsapp-api
```
- `-d`: Run in detached mode.
- `-p`: Map port 3000 on your host to port 3000 in the container.
- `-e`: Set environment variables.
- `--name`: Assign a name to the container.
- `-v`: Mount named volumes to persist data.

---

## 📖 API Documentation

All endpoints are prefixed with `/api`.
Expand Down
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
services:
whatsapp-api:
build: .
container_name: whatsapp_api
restart: unless-stopped
ports:
- "${PORT:-3000}:3000"
environment:
- MASTER_API_KEY=${MASTER_API_KEY:-yoursecretkey}
- PORT=${PORT:-3000}
volumes:
- whatsapp_sessions:/usr/src/app/sessions
- whatsapp_uploads:/usr/src/app/uploads

volumes:
whatsapp_sessions:
whatsapp_uploads: