<?php
$allowedOrigins = [
    "http://localhost:5173",
    "http://localhost:8181",
    "http://localhost:8282",
    "http://192.168.1.100:5173",  // Ganti dengan IP Anda
    "http://192.168.1.100:8181",
    "http://192.168.1.100:8282",
    "https://pbpisumut.com",
    "https://www.pbpisumut.com"
];

$origin = $_SERVER['HTTP_ORIGIN'] ?? '';
if (in_array($origin, $allowedOrigins)) {
    header("Access-Control-Allow-Origin: " . $origin);
    header("Access-Control-Allow-Credentials: true");
}

header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
header("Access-Control-Max-Age: 86400");
/*
$allowedOrigins = [
    "http://localhost:8181",
    "http://localhost:8282"
];

if (isset($_SERVER['HTTP_ORIGIN']) && in_array($_SERVER['HTTP_ORIGIN'], $allowedOrigins)) {
    header("Access-Control-Allow-Origin: " . $_SERVER['HTTP_ORIGIN']);
    header("Access-Control-Allow-Credentials: true");
}

header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
*/
// handle preflight
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    http_response_code(204);
    exit;
}

// load config & helper
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/helpers.php';