mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-04 01:01:35 -07:00
BE: Clean up whitespace in call_api function
This commit is contained in:
@@ -87,7 +87,7 @@ function is_https_request(): bool {
|
|||||||
function call_api(string $endpoint, array $data = []): ?array {
|
function call_api(string $endpoint, array $data = []): ?array {
|
||||||
/*
|
/*
|
||||||
Call NetAlertX API endpoint (for login page endpoints that don't require auth).
|
Call NetAlertX API endpoint (for login page endpoints that don't require auth).
|
||||||
|
|
||||||
Returns: JSON response as array, or null on failure
|
Returns: JSON response as array, or null on failure
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
@@ -95,12 +95,12 @@ function call_api(string $endpoint, array $data = []): ?array {
|
|||||||
$api_host = $_SERVER['HTTP_HOST'] ?? 'localhost';
|
$api_host = $_SERVER['HTTP_HOST'] ?? 'localhost';
|
||||||
$api_scheme = is_https_request() ? 'https' : 'http';
|
$api_scheme = is_https_request() ? 'https' : 'http';
|
||||||
$api_url = $api_scheme . '://' . $api_host;
|
$api_url = $api_scheme . '://' . $api_host;
|
||||||
|
|
||||||
$url = $api_url . $endpoint;
|
$url = $api_url . $endpoint;
|
||||||
|
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
if (!$ch) return null;
|
if (!$ch) return null;
|
||||||
|
|
||||||
curl_setopt_array($ch, [
|
curl_setopt_array($ch, [
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_TIMEOUT => 5,
|
CURLOPT_TIMEOUT => 5,
|
||||||
@@ -110,20 +110,20 @@ function call_api(string $endpoint, array $data = []): ?array {
|
|||||||
'Accept: application/json'
|
'Accept: application/json'
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!empty($data)) {
|
if (!empty($data)) {
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
if ($httpcode !== 200 || !$response) {
|
if ($httpcode !== 200 || !$response) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return json_decode($response, true);
|
return json_decode($response, true);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user