#!/bin/bash
# Setup Nginx config for Nexus POS subdomain routing
# Usage: sudo bash setup-nginx.sh

set -euo pipefail

CONF_SRC="/home/Autopartes/nginx/nexus-pos.conf"
CONF_DEST="/etc/nginx/sites-available/nexus-pos"

echo "==> Copying nginx config..."
sudo cp "$CONF_SRC" "$CONF_DEST"

echo "==> Creating symlink in sites-enabled..."
sudo ln -sf "$CONF_DEST" /etc/nginx/sites-enabled/

echo "==> Testing nginx config..."
if sudo nginx -t; then
    echo "==> Config OK. Reloading nginx..."
    sudo systemctl reload nginx
    echo "==> Done. Subdomain routing active."
else
    echo "!!! Nginx config test failed. NOT reloading."
    exit 1
fi
