# 1. Garage Web Admin UI
garage-ui.yiem.cc {
    reverse_proxy 192.168.88.106:3909
}

# 2. Garage S3 API (Path-Style & Single Domain)
s3-api.yiem.cc {
    # CORS: handle OPTIONS preflight
    @options method OPTIONS {
        header Access-Control-Request-Method *
    }
    handle @options {
        respond * 204
    }
    # CORS headers on all responses
    header {
        Access-Control-Allow-Origin "*"
        Access-Control-Allow-Methods "GET, PUT, POST, DELETE, OPTIONS"
        Access-Control-Allow-Headers "*"
        Access-Control-Max-Age "86400"
    }
    reverse_proxy 192.168.88.106:3900 {
        header_up Host {host}
    }
}

# 3. Garage S3 WEB (Path-Style & Single Domain)
s3-web.yiem.cc {
    # /bucket -> /bucket/
    @bucket_root path_regexp bucket_root ^/([^/]+)$
    redir @bucket_root /{http.regexp.bucket_root.1}/ 301

    # /bucket/... -> Garage
    @bucket path_regexp bucket ^/([^/]+)(/.*)?$

    rewrite @bucket {http.regexp.bucket.2}

    reverse_proxy 192.168.88.106:3902 {
        header_up Host {http.regexp.bucket.1}.s3-web.yiem.cc
    }
}
