# Deployment and Configuration Guide

This guide explains how to toggle the project configuration between **Local Development** and **Production (Server Deployment)**.

---

## 1. How to Toggle Configurations

Use the following table to know which lines to uncomment/comment in each file depending on where you are running the project:

### Frontend config: `cosign-cms-frontend/vite.config.js`
* **Local Development**:
  ```javascript
  proxy: {
    '/api': {
      target: 'http://localhost:5005', // <-- Keep Active
      // target: 'http://beta.cosignconfigurator.com',
      ...
  ```
* **Production**:
  ```javascript
  proxy: {
    '/api': {
      // target: 'http://localhost:5005',
      target: 'http://beta.cosignconfigurator.com', // <-- Keep Active
      ...
  ```

---

### Frontend Env: `cosign-cms-frontend/.env`
* **Local Development**:
  ```env
  VITE_API_URL=http://localhost:5005/api
  # VITE_API_URL=http://beta.cosignconfigurator.com/api
  ```
* **Production**:
  ```env
  # VITE_API_URL=http://localhost:5005/api
  VITE_API_URL=http://beta.cosignconfigurator.com/api
  ```

---

### Backend Env: `cosign-cms-backend/.env`
* **Local Development**:
  ```env
  MONGODB_URI=mongodb://localhost:27017/epaper-cms
  # MONGODB_URI=mongodb+srv://tejaspadaleadcs_db_user:26HsUZMoYfGoQL7Z@epapercms.10xwo6p.mongodb.net/?appName=EpaperCMS

  CORS_ORIGIN=http://localhost:5173
  # CORS_ORIGIN=http://beta.cosignconfigurator.com

  FRONTEND_URL=http://localhost:5173
  # FRONTEND_URL=http://beta.cosignconfigurator.com

  # BACKEND_URL=http://localhost:5005
  # BACKEND_URL=http://beta.cosignconfigurator.com
  ```
* **Production**:
  ```env
  # MONGODB_URI=mongodb://localhost:27017/epaper-cms
  MONGODB_URI=mongodb+srv://tejaspadaleadcs_db_user:26HsUZMoYfGoQL7Z@epapercms.10xwo6p.mongodb.net/?appName=EpaperCMS

  # CORS_ORIGIN=http://localhost:5173
  CORS_ORIGIN=http://beta.cosignconfigurator.com

  # FRONTEND_URL=http://localhost:5173
  FRONTEND_URL=http://beta.cosignconfigurator.com

  # BACKEND_URL=http://localhost:5005
  BACKEND_URL=http://beta.cosignconfigurator.com
  ```

---

## 2. Steps to Deploy Backend Only

1. **Delete node_modules** inside the backend directory to reduce the zip file size:
   ```powershell
   Remove-Item -Recurse -Force cosign-cms-backend\node_modules
   ```
2. **Zip the contents** of the `cosign-cms-backend` folder.
3. **Upload and extract** the zip on the server under `/var/www/epaper-cms-backend`.
4. **Install production dependencies** inside the server directory:
   ```bash
   npm install --omit=dev
   ```
5. **Configure `.env`** on the server to match your production MongoDB Atlas cluster URL and domain names.
6. **Start and manage the server** using PM2:
   ```bash
   npm install -g pm2
   pm2 start server.js --name "epaper-backend"
   pm2 startup
   pm2 save
   ```
