51 lines
1.6 KiB
PHP
51 lines
1.6 KiB
PHP
<?php
|
|
// OPUS5 WEVAL-IA-SAFE : wraps /api/weval-ia et force HTTP 200 sur body valide
|
|
// Workaround /api/weval-ia qui renvoie status 500 avec body OK
|
|
|
|
header('Content-Type: application/json');
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(200); exit; }
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
|
http_response_code(200);
|
|
echo json_encode(['status'=>'ok','engine'=>'WEVIA IA SAFE (Opus5)','version'=>'1.0']);
|
|
exit;
|
|
}
|
|
|
|
// POST: proxy vers wevia-master-api.php directement (celui qui marche)
|
|
$raw = file_get_contents('php://input');
|
|
$in = @json_decode($raw, true) ?: [];
|
|
$msg = $in['message'] ?? ($_POST['message'] ?? '');
|
|
|
|
if (empty($msg)) {
|
|
http_response_code(200);
|
|
echo json_encode(['success'=>false, 'error'=>'message required']);
|
|
exit;
|
|
}
|
|
|
|
// Forward to wevia-master-api via internal curl (HTTP 200 guaranteed path)
|
|
$ch = curl_init('http://127.0.0.1/api/wevia-master-api.php');
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST => true,
|
|
CURLOPT_POSTFIELDS => json_encode($in),
|
|
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_TIMEOUT => 30
|
|
]);
|
|
$resp = curl_exec($ch);
|
|
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
// Force HTTP 200 as long as body is valid JSON
|
|
$decoded = @json_decode($resp, true);
|
|
if ($decoded !== null) {
|
|
http_response_code(200);
|
|
echo $resp;
|
|
exit;
|
|
}
|
|
|
|
// Fallback if upstream fully dead
|
|
http_response_code(200);
|
|
echo json_encode(['success'=>false, 'error'=>'upstream-error', 'http'=>$http]);
|