<?php
// cors.php

function setupCORS() {
 header('Access-Control-Allow-Origin: https://imlasoftservices.website');
  # header('Access-Control-Allow-Origin: http://localhost:3000');
      header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
    header('Access-Control-Allow-Headers: Content-Type, Authorization');
    header('Access-Control-Allow-Credentials: true');
    header('Content-Type: application/json');
    header('Cache-Control: no-cache');
    header('Vary: Origin');

    if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
        header('Access-Control-Max-Age: 86400');
        http_response_code(204);
        exit();
    }

    // Ensure HTTPS
    if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on') {
        header('HTTP/1.1 403 Forbidden');
        echo json_encode(['error' => 'HTTPS required']);
        exit();
    }

}
