diff --git a/backend/src/index.ts b/backend/src/index.ts index 56288ee..1d9845a 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -17,8 +17,7 @@ const sessionSecret = process.env.SESSION_SECRET; if (!sessionSecret) throw new Error("SESSION_SECRET env var is required"); const app = Fastify({ - // In prod: warn-level only to reduce noise; in dev: full pretty logging - logger: isProd ? { level: "warn" } : true, + logger: isProd ? { level: "info" } : true, // Trust the nginx reverse proxy so secure cookies and req.ip work correctly trustProxy: isProd, }); diff --git a/backend/src/routes/auth.ts b/backend/src/routes/auth.ts index 60aadfd..218c505 100644 --- a/backend/src/routes/auth.ts +++ b/backend/src/routes/auth.ts @@ -80,7 +80,8 @@ export const authRouter: FastifyPluginAsync = async (fastify) => { req.session.user = user; const base = process.env.FRONTEND_APP_URL ?? "http://localhost:5173"; - reply.redirect(`${base}?login=1`); + const baseUrl = base.endsWith("/") ? base : `${base}/`; + reply.redirect(`${baseUrl}?login=1`); }, ); diff --git a/deploy.sh b/deploy.sh index fb6132c..83d3c86 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,19 +1,54 @@ #!/bin/bash set -e -echo "Pulling latest code..." -git pull +# Usage: ./deploy.sh [options] [target] +# Target: all (default), backend, frontend +# Options: --no-pull -echo "Building frontend..." -docker compose --profile build build frontend-builder -docker compose --profile build run --rm frontend-builder +TARGET="all" +NO_PULL=false -echo "Copying frontend dist to nginx..." -sudo mkdir -p /var/www/support-ticket-demo -sudo cp -r frontend/dist/. /var/www/support-ticket-demo/ +# Parse arguments +for arg in "$@"; do + case $arg in + --no-pull) + NO_PULL=true + ;; + backend|frontend|all) + TARGET=$arg + ;; + *) + echo "Unknown argument: $arg" + echo "Usage: $0 [--no-pull] [all|backend|frontend]" + exit 1 + ;; + esac +done -echo "Building and restarting backend..." -docker compose up -d --build --remove-orphans backend +# Git pull +if [ "$NO_PULL" = false ]; then + echo "Pulling latest code..." + git pull +else + echo "Skipping git pull..." +fi + +# Deploy frontend +if [ "$TARGET" = "all" ] || [ "$TARGET" = "frontend" ]; then + echo "Building frontend..." + docker compose --profile build build frontend-builder + docker compose --profile build run --rm frontend-builder + + echo "Copying frontend dist to nginx..." + sudo mkdir -p /var/www/support-ticket-demo + sudo cp -r frontend/dist/. /var/www/support-ticket-demo/ +fi + +# Deploy backend +if [ "$TARGET" = "all" ] || [ "$TARGET" = "backend" ]; then + echo "Building and restarting backend..." + docker compose up -d --build --remove-orphans backend +fi echo "Cleaning up old images..." docker image prune -f