#!/usr/bin/env php getMessage()}\n"); exit(1); } if (!isset($data['domains']) || !is_array($data['domains'])) { fwrite(STDERR, "Expected a \"domains\" array in $jsonFile\n"); exit(1); } $domains = []; foreach ($data['domains'] as $entry) { $host = is_array($entry) ? ($entry['domain'] ?? null) : $entry; $host = is_string($host) ? trim($host) : ''; if ($host === '') { continue; } if (!preg_match('/^[a-z0-9.-]+$/i', $host)) { fwrite(STDERR, "Skipping invalid domain: \"$host\"\n"); continue; } $domains[strtolower($host)] = true; // dedupe, case-insensitive } $domains = array_keys($domains); sort($domains); if (empty($domains)) { fwrite(STDERR, "No valid domains found in $jsonFile\n"); exit(1); } // CORS: explicit alternation, anchored, dots escaped. https only. $alternation = implode('|', array_map(static fn (string $d): string => preg_quote($d, '/'), $domains)); $cors = "^https://($alternation)$"; // Frontend hosts: bare hostnames, comma-separated (matched via in_array in PaymentController). $hosts = implode(',', $domains); echo "# ---- paste into Coolify env (" . count($domains) . " domains) ----\n\n"; echo "CORS_ALLOW_ORIGIN='" . $cors . "'\n\n"; echo "ALLOWED_FRONTEND_HOSTS=" . $hosts . "\n";