services:
    # postgres:
    #     image: postgres:15-alpine
    #     working_dir: /application
    #     volumes:
    #         - .:/application
    #     environment:
    #         - POSTGRES_USER=postgres
    #         - POSTGRES_PASSWORD=psql
    #         - POSTGRES_DB=printing_shop_db
    #     ports:
    #         - "27004:5432"
    #     healthcheck:
    #         test:
    #             [
    #                 "CMD-SHELL",
    #                 "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB} -h 127.0.0.1 -p 5432",
    #             ]
    #         interval: 3s
    #         timeout: 3s
    #         retries: 20

    app:
        build: phpdocker/frankenphp
        working_dir: /app
        ports:
            - "80:80"
            - "443:443"
            # (dev only) expose Vite if you want HMR:
            - "5173:5173"
        volumes:
            - ./:/app
            - ./Caddyfile:/etc/caddy/Caddyfile:ro
            - caddy_data:/data
            - caddy_config:/config
        environment:
            # Recommended: ACME account email for auto-HTTPS
            # ACME_EMAIL: you@example.com
            # Optional: gate on-demand TLS to allowed hostnames (URL that returns 200 if allowed)
            ON_DEMAND_ASK:
            # (dev only) set VITE_HOST=0.0.0.0 in your env if running HMR inside the container

            CANONICAL_DOMAIN: ${APP_URL}
            WWW_DOMAIN: www.${APP_URL}
        healthcheck:
            test:
                [
                    "CMD-SHELL",
                    "wget -qO- http://127.0.0.1/health >/dev/null 2>&1 || exit 1",
                ]
            interval: 5s
            timeout: 3s
            retries: 20

    # php-fpm:
    #     build: phpdocker/php-fpm
    #     working_dir: /application
    #     volumes:
    #         - ".:/application"
    #         - "/application/node_modules"
    #         - "./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/8.4/fpm/conf.d/99-overrides.ini"
    #         - "./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/8.4/cli/conf.d/99-overrides.ini"
    #     ports:
    #         - "5173:5173"
    #     healthcheck:
    #         # Checks PHP-FPM is up (port 5173) and PHP CLI is usable
    #         test:
    #             [
    #                 "CMD-SHELL",
    #                 "php -v >/dev/null 2>&1 && (nc -z 127.0.0.1 5173 || ss -ltn | grep -q ':5173')",
    #             ]
    #         interval: 5s
    #         timeout: 3s
    #         retries: 30

volumes:
    caddy_data:
    caddy_config:
