mirror of
https://github.com/myronblair/epictravelexpeditions
synced 2026-06-30 17:50:08 -05:00
84 lines
2.2 KiB
PHP
84 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* Epic Travel & Expeditions - Main API Entry Point
|
|
* This file routes all API requests to appropriate handlers
|
|
*/
|
|
|
|
// Load configuration and dependencies
|
|
require_once __DIR__ . '/config.php';
|
|
require_once __DIR__ . '/includes/database.php';
|
|
require_once __DIR__ . '/includes/jwt.php';
|
|
require_once __DIR__ . '/includes/functions.php';
|
|
require_once __DIR__ . '/includes/mailer.php';
|
|
|
|
// Set CORS headers (handles OPTIONS preflight too)
|
|
setCorsHeaders();
|
|
|
|
// Get request method and path
|
|
$method = $_SERVER['REQUEST_METHOD'];
|
|
$path = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/';
|
|
$path = trim($path, '/');
|
|
|
|
// Parse path
|
|
$pathParts = explode('/', $path);
|
|
$resource = isset($pathParts[0]) ? $pathParts[0] : '';
|
|
$id = isset($pathParts[1]) ? $pathParts[1] : null;
|
|
|
|
// Health check endpoint
|
|
if ($path === '' || $path === 'api') {
|
|
jsonResponse([
|
|
'message' => 'Epic Travel API is running',
|
|
'status' => 'healthy'
|
|
]);
|
|
}
|
|
|
|
// Route to appropriate handler
|
|
try {
|
|
switch ($resource) {
|
|
case 'auth':
|
|
require __DIR__ . '/api/auth.php';
|
|
break;
|
|
|
|
case 'destinations':
|
|
require __DIR__ . '/api/destinations.php';
|
|
break;
|
|
|
|
case 'specials':
|
|
require __DIR__ . '/api/specials.php';
|
|
break;
|
|
|
|
case 'contact':
|
|
require __DIR__ . '/api/contact.php';
|
|
break;
|
|
|
|
case 'newsletter':
|
|
require __DIR__ . '/api/newsletter.php';
|
|
break;
|
|
|
|
case 'upload':
|
|
require __DIR__ . '/api/upload.php';
|
|
break;
|
|
|
|
case 'download':
|
|
require __DIR__ . '/api/download.php';
|
|
break;
|
|
|
|
case 'testimonials':
|
|
require __DIR__ . '/api/testimonials.php';
|
|
break;
|
|
|
|
case 'categories':
|
|
require __DIR__ . '/api/categories.php';
|
|
break;
|
|
|
|
default:
|
|
jsonResponse(['error' => 'Endpoint not found'], 404);
|
|
}
|
|
} catch (Exception $e) {
|
|
if (DEBUG_MODE) {
|
|
jsonResponse(['error' => $e->getMessage()], 500);
|
|
} else {
|
|
jsonResponse(['error' => 'Internal server error'], 500);
|
|
}
|
|
}
|