#!/bin/sh

# Docker entrypoint for Queue North Website
# The Dockerfile uses USER nodejs + CMD directly, so this script
# is only used if explicitly set as ENTRYPOINT.
# It ensures db/logs directories exist before starting the server.

set -e

# Create directories if they don't exist
mkdir -p /app/db
mkdir -p /app/logs

# Ensure proper ownership (runs as root before su-exec)
chown -R nodejs:nodejs /app/db /app/logs 2>/dev/null || true

# Run as nodejs user if currently root
if [ "$(id -u)" = "0" ]; then
  exec su-exec nodejs node server/index.js
else
  exec node server/index.js
fi