Initial commit: Retribusi frontend dengan dashboard, event logs, dan settings
This commit is contained in:
30
api/cors-handler.php
Normal file
30
api/cors-handler.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* CORS Handler untuk API Btekno
|
||||
*
|
||||
* File ini HARUS di-include di awal SETIAP endpoint PHP
|
||||
* atau ditempatkan di file bootstrap/autoload yang dieksekusi sebelum semua endpoint
|
||||
*
|
||||
* Usage:
|
||||
* require_once __DIR__ . '/cors-handler.php';
|
||||
*/
|
||||
|
||||
// Set CORS headers
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-API-KEY");
|
||||
header("Access-Control-Max-Age: 3600");
|
||||
header("Access-Control-Allow-Credentials: false");
|
||||
|
||||
// Handle preflight OPTIONS request
|
||||
// Browser akan mengirim OPTIONS request sebelum POST/PUT/DELETE jika ada custom headers
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
||||
http_response_code(200);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Log untuk debugging (opsional, bisa dihapus di production)
|
||||
if (defined('APP_DEBUG') && APP_DEBUG === true) {
|
||||
error_log('CORS Handler: ' . $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user