first working draft

This commit is contained in:
2025-09-19 21:39:52 +02:00
parent 1e223ceacc
commit 8c03eed484
6 changed files with 39 additions and 19 deletions

View File

@@ -1,6 +1,14 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/../src/Calco2ApiClient.php';
require_once __DIR__ . '/../src/Calco2latoApiClient.php';
$env = file_get_contents(__DIR__."/../src/.env");
$lines = explode("\n",$env);
foreach($lines as $line){
preg_match("/([^#]+)\=(.*)/",$line,$matches);
if(isset($matches[2])){ putenv(trim($line)); }
}
// --- Basic CORS (adjust origin to your site/domain) ---
$origin = $_SERVER['HTTP_ORIGIN'] ?? '';
@@ -44,7 +52,7 @@ if (!$key) {
echo json_encode(['error' => 'Server misconfiguration: missing API key']);
exit;
}
$client = new Calco2ApiClient($base, $key);
$client = new Calco2latoApiClient($base, $key);
// --- Whitelist router ---
$input = json_decode(file_get_contents('php://input') ?: '[]', true) ?: [];
@@ -56,11 +64,11 @@ header('Content-Type: application/json; charset=utf-8');
try {
switch ($endpoint) {
case 'airports.search':
// GET /?endpoint=airports.search&q=FRA&limit=10
// GET /?endpoint=airports.search&q=FRA&per_page=10
$q = $_GET['q'] ?? '';
$limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 20;
$offset= isset($_GET['offset']) ? (int)$_GET['offset'] : 0;
$data = $client->searchAirports($q, $limit, $offset);
$per_page = isset($_GET['per_page']) ? (int)$_GET['per_page'] : 20;
$page= isset($_GET['page']) ? (int)$_GET['page'] : 1;
$data = $client->searchAirports($q, $per_page, $page);
echo json_encode($data);
break;