## Recent changes

- **Loader stuck fix (Feb 2025):** App no longer stays stuck on the initial loader. Router now initializes when `Roles.subscription.ready()` is true, or when the user is not logged in (no roles needed for landing), or after a 4s timeout so the site always loads even if the roles subscription never becomes ready (e.g. DDP/connection issues). See `imports/routes/router.js`.
- **GTM and Intercom console errors:** Use **ROOT_URL=https://www.everyspace.co.za/** (trailing slash) in Docker. Fix Intercom 403 by adding `https://www.everyspace.co.za` (and `https://everyspace.co.za` if used) to Intercom's allowed domains. GTM snippet is wrapped in try/catch; Intercom widget loads after app mount so failures don't break the app. See `docs/fix-gtm-intercom-console-errors.md`.

## Node.js Version Requirements

### Production (Docker Deployment)
- **Node.js 14.18.1** - This is automatically used in the Docker container (specified in Dockerfile)

### Local Development
- **Node.js 12.13.0** - For installing dependencies (`npm install`)
- **Node.js 10.16.0** - For running the gulp process

**Note:** The Docker deployment uses Node 14.18.1, so you don't need to install Node.js on the server if deploying with Docker.

##17 June 2022
Devs use node version 12.13.0 to install dependencies and then node version 10.16.0 to run the gulp process

clone foundation-sites(6.5.3) into `/packages` directory

``$ npm install``

``$ npm start``

####Email Templates:
You can grab email templates from an existing email in your email client by
downloading the .eml file and using https://github.com/amitevski/eml_to_html.git
to extract the html. Just interpolate your variables.


Deploy New Build:

`$ meteor build ..\build\ --server-only ; scp ..\build\filmspace-meteor_react.tar.gz codeswop@filmspace.codeswop.com:~ ; ssh codeswop@filmspace.codeswop.com "tar -zxf filmspace-meteor_react.tar.gz -C filmspace/app/ && pm2 restart 0"`

Update pm2.json and restart app

`$ scp pm2.json codeswop@filmspace.codeswop.com:~/filmspace/app ; ssh codeswop@filmspace.codeswop.com "pm2 restart filmspace/app/pm2.json"`

Deploy New Build (filmspace.co.za):

`$ scp pm2.json codeswop@filmspace.co.za:~/app ; ssh codeswop@filmspace.co.za "pm2 restart app/pm2.json"`

`$ meteor build ..\build\ --server-only ; scp ..\build\filmspace-meteor_react.tar.gz codeswop@filmspace.co.za:~ ; ssh codeswop@filmspace.co.za "tar -zxf filmspace-meteor_react.tar.gz -C app/ && pm2 restart 0"`

### Upgrades Jan 2021

- Week 1 - (10 Feb - 15Feb) - US-5 - Filepull Overhaul / Download image.
- Week 2 - (16Feb - 22Feb) - US-2 Spaces Tags.
- Week 3 - (23 Feb - 03 Mar) - US-3 Search Page Mapping - CPT, JHB, DRB & GR.
- Week 4 - (04 Mar - 08 Mar) - US-4 Back-end user content override.
- Week 5 - (09 March - 11 March) - US-11 Host & Filmmaker Message Notifications & US-8 Zero Service Fees.
- Week 6 (12 March - 15 March) - US-7 Keep all comms on Filmspace block / US-6 Minimum Hours Tooltip / US-10 Listing process remove items / US-9 User Feedback Modal - Push to Log in / US-12 Intercom Chatbot.

Mysterious failure of build pipeline occurred. Could have been a deps conflict, but even after removing the only
package that was installed it still failed with errors that I couldn't relate to the package itself. Eventually fixed
by checking out last working commit and applying the same changes in app source and pushing to CI

### Docker Commands

Build
```shell
docker build -t everyspace:latest .
```
Run
```shell
docker run --rm -p 3000:3000 --name everyspace -d `
--env ROOT_URL=http://localhost:3000 `
--env MONGO_URL=mongodb+srv://codeswop:cmxa7N2GVDmSg%23L@filmspacecluster-2bflv.mongodb.net/filmspace_dev `
--env ACTIVE_CAMPAIGN_URL=https://filmspace.api-us1.com `
--env ACTIVE_CAMPAIGN_KEY=4d1db771fd55525fecf21f80e985998a070d9f8b6f65e28d3ec5ce5ff3ad9e25a62d7351 `
--env ACTIVE_CAMPAIGN_TRACK_KEY=55a0fb0386f7ab1d200fc2a6ba9a337535fcd728 `
--env ACTIVE_CAMPAIGN_TRACK_ACCOUNT_ID=649888565 `
--env DO_ACCESS_KEY=AKIAZXCQO5FZZY2X54VU `
--env DO_SECRET=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 `
--env MAIL_URL=smtps://hello@filmspace.co.za:fILMSPACEgENERAL19@smtp.gmail.com:465 `
everyspace
```
The newer meteor multistage build requires a different approach to build gitlab artifacts.

Too build the tar:

```shell
...
docker build -t everyspace:latest .
docker container create --name everyspace-app everyspace:latest
docker container cp everyspace-app:/app.tar.gz .
docker container rm everyspace-app
```

### DB
Restore Live to Local

```mongorestore -h 127.0.0.1 --port 3001 --db meteor ..\dump\filmspace```

Transform pricing schema

```mongo mongodb://127.0.0.1:3001/meteor .\db\scripts\pricing-migrate.js```

Transform pricing schema 2

```mongo mongodb://127.0.0.1:3001/meteor .\db\scripts\pricing-minMax.js```

Assign Random activities to listings to test search

```mongo mongodb://127.0.0.1:3001/meteor .\db\scripts\random-activities-for-testing.js```

11 Novemeber 2025

``` docker run --rm --network host --name everyspace -d   --env ROOT_URL=http://156.38.132.154:3000/   --env PORT=3000   --env BIND_IP=0.0.0.0   --env MONGO_URL=mongodb://everyspaceAdmin:everyspace@127.0.0.1:27017/everyspace   --env ACTIVE_CAMPAIGN_URL=https://filmspace.api-us1.com   --env ACTIVE_CAMPAIGN_KEY=4d1db771fd55525fecf21f80e985998a070d9f8b6f65e28d3ec5ce5ff3ad9e25a62d7351   --env ACTIVE_CAMPAIGN_TRACK_KEY=55a0fb0386f7ab1d200fc2a6ba9a337535fcd728   --env ACTIVE_CAMPAIGN_TRACK_ACCOUNT_ID=649888565   --env DO_ACCESS_KEY=AKIAZXCQO5FZZY2X54VU   --env DO_SECRET=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   --env MAIL_URL=smtps://hello@filmspace.co.za:fILMSPACEgENERAL19@smtp.gmail.com:465   everyspace ```

``` docker run --rm --network host --name everyspace -d   --env ROOT_URL=http://127.0.0.1:3000/   --env PORT=3000   --env BIND_IP=0.0.0.0   --env MONGO_URL=mongodb://everyspaceAdmin:everyspace@156.38.132.154:27017/everyspace   --env ACTIVE_CAMPAIGN_URL=https://filmspace.api-us1.com   --env ACTIVE_CAMPAIGN_KEY=4d1db771fd55525fecf21f80e985998a070d9f8b6f65e28d3ec5ce5ff3ad9e25a62d7351   --env ACTIVE_CAMPAIGN_TRACK_KEY=55a0fb0386f7ab1d200fc2a6ba9a337535fcd728   --env ACTIVE_CAMPAIGN_TRACK_ACCOUNT_ID=649888565   --env DO_ACCESS_KEY=AKIAZXCQO5FZZY2X54VU   --env DO_SECRET=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   --env MAIL_URL=smtps://hello@filmspace.co.za:fILMSPACEgENERAL19@smtp.gmail.com:465   everyspace ```

**Note for Windows:** `--network host` doesn't work on Windows Docker Desktop. Use port mapping instead:
```docker run --rm -p 3000:3000 --name everyspace -d   --env ROOT_URL=http://127.0.0.1:3000/   --env PORT=3000   --env BIND_IP=0.0.0.0   --env MONGO_URL=mongodb://everyspaceAdmin:everyspace@156.38.132.154:27017/everyspace   --env ACTIVE_CAMPAIGN_URL=https://filmspace.api-us1.com   --env ACTIVE_CAMPAIGN_KEY=4d1db771fd55525fecf21f80e985998a070d9f8b6f65e28d3ec5ce5ff3ad9e25a62d7351   --env ACTIVE_CAMPAIGN_TRACK_KEY=55a0fb0386f7ab1d200fc2a6ba9a337535fcd728   --env ACTIVE_CAMPAIGN_TRACK_ACCOUNT_ID=649888565   --env DO_ACCESS_KEY=AKIAZXCQO5FZZY2X54VU   --env DO_SECRET=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   --env MAIL_URL=smtps://hello@filmspace.co.za:fILMSPACEgENERAL19@smtp.gmail.com:465   everyspace```

**Run from WSL/Ubuntu (Windows):**
To run Docker from WSL on Windows, use this command (adjust the WSL distribution name and path as needed):
```bash
wsl -d Ubuntu-24.04 bash -c "cd /mnt/c/wamp64/www/everspace && docker run --rm -p 3000:3000 --name everyspace -d --env ROOT_URL=http://127.0.0.1:3000/ --env PORT=3000 --env BIND_IP=0.0.0.0 --env MONGO_URL=mongodb://everyspaceAdmin:everyspace@156.38.132.154:27017/everyspace --env ACTIVE_CAMPAIGN_URL=https://filmspace.api-us1.com --env ACTIVE_CAMPAIGN_KEY=4d1db771fd55525fecf21f80e985998a070d9f8b6f65e28d3ec5ce5ff3ad9e25a62d7351 --env ACTIVE_CAMPAIGN_TRACK_KEY=55a0fb0386f7ab1d200fc2a6ba9a337535fcd728 --env ACTIVE_CAMPAIGN_TRACK_ACCOUNT_ID=649888565 --env DO_ACCESS_KEY=AKIAZXCQO5FZZY2X54VU --env DO_SECRET=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 everyspace"
```

**Note:** The MAIL_URL environment variable is omitted in the WSL command above because Gmail authentication requires app-specific passwords. If you need email functionality, generate an app-specific password for the Gmail account and include `--env MAIL_URL=smtps://hello@filmspace.co.za:YOUR_APP_PASSWORD@smtp.gmail.com:465` in the command.

### Deployment on Ubuntu Server

#### Prerequisites
1. **Ubuntu Server** (20.04 or later recommended)
2. **Docker** installed and running
3. **MongoDB** accessible (either local or remote)
4. **Domain name** (optional, for production) or **public IP address**

#### Step 1: Install Docker on Ubuntu Server
```bash
# Update package index
sudo apt update

# Install prerequisites
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common

# Add Docker's official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# Add Docker repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Install Docker
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io

# Start and enable Docker
sudo systemctl start docker
sudo systemctl enable docker

# Add your user to docker group (optional, to run docker without sudo)
sudo usermod -aG docker $USER
# Log out and back in for group changes to take effect
```

#### Step 2: Transfer Code to Server
```bash
# On your local machine, compress the project (excluding node_modules, .meteor)
tar --exclude='node_modules' --exclude='.meteor/local' --exclude='.git' -czf everyspace.tar.gz .

# Transfer to server
scp everyspace.tar.gz user@your-server-ip:~/

# On server, extract
ssh user@your-server-ip
cd ~
mkdir -p everyspace
tar -xzf everyspace.tar.gz -C everyspace/
cd everyspace
```

#### Step 3: Build Docker Image on Server
```bash
cd ~/everyspace
docker build -t everyspace:latest .
```

#### Step 4: Run Container with Proper Configuration
Replace `YOUR_SERVER_IP` with your actual server IP or domain name:

```bash
# Stop existing container if running
docker stop everyspace 2>/dev/null || true
docker rm everyspace 2>/dev/null || true

# Run the container
docker run --rm --network host --name everyspace -d \
  --env ROOT_URL=http://YOUR_SERVER_IP:3000/ \
  --env PORT=3000 \
  --env BIND_IP=0.0.0.0 \
  --env MONGO_URL=mongodb://everyspaceAdmin:everyspace@156.38.132.154:27017/everyspace \
  --env ACTIVE_CAMPAIGN_URL=https://filmspace.api-us1.com \
  --env ACTIVE_CAMPAIGN_KEY=4d1db771fd55525fecf21f80e985998a070d9f8b6f65e28d3ec5ce5ff3ad9e25a62d7351 \
  --env ACTIVE_CAMPAIGN_TRACK_KEY=55a0fb0386f7ab1d200fc2a6ba9a337535fcd728 \
  --env ACTIVE_CAMPAIGN_TRACK_ACCOUNT_ID=649888565 \
  --env DO_ACCESS_KEY=AKIAZXCQO5FZZY2X54VU \
  --env DO_SECRET=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 \
  --env MAIL_URL=smtps://hello@filmspace.co.za:fILMSPACEgENERAL19@smtp.gmail.com:465 \
  everyspace:latest
```

**For production with domain name:**
```bash
docker run --rm --network host --name everyspace -d \
  --env ROOT_URL=https://yourdomain.com/ \
  --env PORT=3000 \
  --env BIND_IP=0.0.0.0 \
  --env MONGO_URL=mongodb://everyspaceAdmin:everyspace@156.38.132.154:27017/everyspace \
  --env ACTIVE_CAMPAIGN_URL=https://filmspace.api-us1.com \
  --env ACTIVE_CAMPAIGN_KEY=4d1db771fd55525fecf21f80e985998a070d9f8b6f65e28d3ec5ce5ff3ad9e25a62d7351 \
  --env ACTIVE_CAMPAIGN_TRACK_KEY=55a0fb0386f7ab1d200fc2a6ba9a337535fcd728 \
  --env ACTIVE_CAMPAIGN_TRACK_ACCOUNT_ID=649888565 \
  --env DO_ACCESS_KEY=AKIAZXCQO5FZZY2X54VU \
  --env DO_SECRET=qaja1HZ5KWB92fzvQYyFT0fICIEg77FYf6AfV7M4 \
  --env MAIL_URL=smtps://hello@filmspace.co.za:YOUR_APP_PASSWORD@smtp.gmail.com:465 \
  everyspace:latest
```

#### Step 5: Configure Firewall (UFW)
```bash
# Allow SSH (important!)
sudo ufw allow 22/tcp

# Allow application port
sudo ufw allow 3000/tcp

# Enable firewall
sudo ufw enable

# Check status
sudo ufw status
```

#### Step 6: Set Up Nginx Reverse Proxy (Optional but Recommended)
Install Nginx:
```bash
sudo apt install -y nginx
```

Create Nginx configuration:
```bash
sudo nano /etc/nginx/sites-available/everyspace
```

Add this configuration (replace `yourdomain.com` with your domain or IP):
```nginx
server {
    listen 80;
    server_name yourdomain.com;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
    }
}
```

Enable site:
```bash
sudo ln -s /etc/nginx/sites-available/everyspace /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
```

#### Step 7: Set Up SSL with Let's Encrypt (Optional but Recommended)
```bash
# Install Certbot
sudo apt install -y certbot python3-certbot-nginx

# Get SSL certificate (replace with your domain)
sudo certbot --nginx -d yourdomain.com

# Auto-renewal is set up automatically
```

#### Step 8: Set Up Auto-Restart with Docker Restart Policy
```bash
# Stop current container
docker stop everyspace

# Run with restart policy
docker run --restart unless-stopped --network host --name everyspace -d \
  --env ROOT_URL=https://yourdomain.com/ \
  --env PORT=3000 \
  --env BIND_IP=0.0.0.0 \
  --env MONGO_URL=mongodb://everyspaceAdmin:everyspace@156.38.132.154:27017/everyspace \
  --env ACTIVE_CAMPAIGN_URL=https://filmspace.api-us1.com \
  --env ACTIVE_CAMPAIGN_KEY=4d1db771fd55525fecf21f80e985998a070d9f8b6f65e28d3ec5ce5ff3ad9e25a62d7351 \
  --env ACTIVE_CAMPAIGN_TRACK_KEY=55a0fb0386f7ab1d200fc2a6ba9a337535fcd728 \
  --env ACTIVE_CAMPAIGN_TRACK_ACCOUNT_ID=649888565 \
  --env DO_ACCESS_KEY=AKIAZXCQO5FZZY2X54VU \
  --env DO_SECRET=qaja1HZ5KWB92fzvQYyFT0fICIEg77FYf6AfV7M4 \
  --env MAIL_URL=smtps://hello@filmspace.co.za:YOUR_APP_PASSWORD@smtp.gmail.com:465 \
  everyspace:latest
```

#### Useful Docker Commands
```bash
# View logs
docker logs -f everyspace

# Check container status
docker ps

# Stop container
docker stop everyspace

# Start container
docker start everyspace

# Restart container
docker restart everyspace

# Remove container
docker rm everyspace

# Rebuild and redeploy
docker stop everyspace
docker rm everyspace
docker build -t everyspace:latest .
# Then run the docker run command again
```

#### Troubleshooting
1. **Container won't start**: Check logs with `docker logs everyspace`
2. **Can't access from browser**: Check firewall rules and ROOT_URL matches your domain/IP
3. **MongoDB connection issues**: Verify MongoDB is accessible from the server
4. **Email not working**: Generate Gmail app-specific password and update MAIL_URL