43 lines
1.1 KiB
Plaintext
43 lines
1.1 KiB
Plaintext
|
|
<?php
|
||
|
|
/**
|
||
|
|
* EXAMPLE: Dashboard Summary Endpoint dengan CORS Handler
|
||
|
|
*
|
||
|
|
* INSTRUKSI:
|
||
|
|
* 1. Copy kode CORS handler ke paling atas
|
||
|
|
* 2. Pastikan CORS handler dieksekusi SEBELUM logic auth
|
||
|
|
*/
|
||
|
|
|
||
|
|
// ================= CORS HANDLER (WAJIB PALING ATAS) =================
|
||
|
|
header("Access-Control-Allow-Origin: *");
|
||
|
|
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
|
||
|
|
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-API-KEY");
|
||
|
|
|
||
|
|
// Handle preflight OPTIONS request
|
||
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
||
|
|
http_response_code(200);
|
||
|
|
exit;
|
||
|
|
}
|
||
|
|
// ================= END CORS HANDLER =================
|
||
|
|
|
||
|
|
// Set header untuk JSON response
|
||
|
|
header('Content-Type: application/json');
|
||
|
|
|
||
|
|
// Logic auth/validation di sini
|
||
|
|
// ... kode auth yang sudah ada ...
|
||
|
|
|
||
|
|
// Logic summary di sini
|
||
|
|
// ... kode summary yang sudah ada ...
|
||
|
|
|
||
|
|
// Example response (sesuaikan dengan logic yang sudah ada)
|
||
|
|
/*
|
||
|
|
$response = [
|
||
|
|
'date' => '2024-01-01',
|
||
|
|
'location_code' => null,
|
||
|
|
'total_vehicle' => 100,
|
||
|
|
'total_person' => 250,
|
||
|
|
'total_amount' => 5000000
|
||
|
|
];
|
||
|
|
echo json_encode($response);
|
||
|
|
*/
|
||
|
|
|