46 lines
1.5 KiB
PHP
46 lines
1.5 KiB
PHP
<?php
|
||
/**
|
||
* V85 Business KPI Dashboard endpoint
|
||
* V96.19 Opus · forward alias to wevia-v83-business-kpi.php
|
||
*
|
||
* HTML WTP line 1468 expects: /api/wevia-v83-business-kpi.php?action=full + action=summary
|
||
* But shows "Loading V85 business KPIs (7 categories × 8 KPIs = 56)..." stuck because
|
||
* fetch goes to /api/v85-business-kpi.php which returns 404.
|
||
*
|
||
* Root cause: missing forward endpoint. This file resolves it.
|
||
* Doctrine #13 cause racine: alias/bridge the expected call to existing backend.
|
||
*/
|
||
header('Content-Type: application/json; charset=utf-8');
|
||
header('Access-Control-Allow-Origin: *');
|
||
|
||
$action = $_REQUEST['action'] ?? 'summary';
|
||
$allowed = ['summary', 'full', 'category', 'actionable'];
|
||
if (!in_array($action, $allowed)) $action = 'summary';
|
||
|
||
// Build query string forward
|
||
$qs = http_build_query($_REQUEST);
|
||
$url = 'http://127.0.0.1:5890/api/wevia-v83-business-kpi.php?' . $qs;
|
||
|
||
$ctx = stream_context_create(['http' => ['timeout' => 15]]);
|
||
$data = @file_get_contents($url, false, $ctx);
|
||
|
||
if ($data === false) {
|
||
http_response_code(502);
|
||
echo json_encode([
|
||
'error' => 'backend_unreachable',
|
||
'upstream' => '/api/wevia-v83-business-kpi.php',
|
||
'v' => 'V96.19-v85-alias',
|
||
]);
|
||
exit;
|
||
}
|
||
|
||
// Pass-through with note
|
||
$parsed = json_decode($data, true);
|
||
if (is_array($parsed)) {
|
||
$parsed['_forwarded_by'] = 'v85-business-kpi.php → wevia-v83-business-kpi.php';
|
||
$parsed['_v'] = 'V96.19-v85-alias-opus';
|
||
echo json_encode($parsed, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||
} else {
|
||
echo $data;
|
||
}
|