#!/bin/sh
# dispatch-frontend service — serves the built frontend assets as the `tradam` user.
# stdout/stderr are piped to dispatch-frontend-log via the s6-rc pipeline.

DISPATCH_CONF="/etc/dispatch/dispatch-frontend.conf"
DISPATCH_DIR="/opt/dispatch"

if [ -f "$DISPATCH_CONF" ]; then
    set -a
    . "$DISPATCH_CONF"
    set +a
fi

cd "$DISPATCH_DIR" || exit 1

exec 2>&1

exec /usr/bin/s6-setuidgid tradam \
    /usr/bin/env \
        HOME=/home/tradam \
        USER=tradam \
        LOGNAME=tradam \
        PATH=/usr/local/bin:/usr/bin:/bin \
        PORT="${PORT:-18391}" \
    /usr/bin/bun packages/frontend/serve.ts
