index.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. declare(strict_types=1);
  3. header('X-EKSRelay: hit');
  4. file_put_contents(__DIR__ . '/../logs/_probe.txt', "probe " . date('c') . "\n", FILE_APPEND);
  5. /**
  6. * EKSRelay – single entry point.
  7. *
  8. * Run: php -S 0.0.0.0:8080 -t public
  9. */
  10. require_once __DIR__ . '/../vendor/autoload.php';
  11. use EKSRelay\Core\Env;
  12. use EKSRelay\Core\Logger;
  13. use EKSRelay\Core\Router;
  14. use EKSRelay\Handlers\ChatwootWebhookHandler;
  15. use EKSRelay\Handlers\NewTicketHandler;
  16. use EKSRelay\Handlers\WooToolsHandler;
  17. // ── Bootstrap ──────────────────────────────────────────────────────
  18. Env::load(__DIR__ . '/../.env');
  19. Logger::init();
  20. // ── Routes ─────────────────────────────────────────────────────────
  21. $router = new Router();
  22. // Chatwoot webhook
  23. $router->post('/webhooks/chatwoot', [ChatwootWebhookHandler::class, 'handle']);
  24. // Tools (called by Flowise or external)
  25. $router->post('/tools/new_ticket', [NewTicketHandler::class, 'handle']);
  26. $router->post('/tools/get_order_data', [WooToolsHandler::class, 'getOrderData']);
  27. $router->post('/tools/get_product_data', [WooToolsHandler::class, 'getProductData']);
  28. $router->post('/tools/get_shipping_data', [WooToolsHandler::class, 'getShippingData']);
  29. $router->post('/tools/get_payment_methods', [WooToolsHandler::class, 'getPaymentMethods']);
  30. $router->post('/tools/get_product_compatibility', [WooToolsHandler::class, 'getProductCompatibility']);
  31. $router->post('/tools/get_car_data', [WooToolsHandler::class, 'getCarData']);
  32. // ── Dispatch ───────────────────────────────────────────────────────
  33. $method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
  34. $path = $_GET['__path']
  35. ?? (parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/');
  36. $path = '/' . trim((string)$path, '/');
  37. $rawBody = file_get_contents('php://input') ?: '';
  38. Logger::info('Incoming request', [
  39. 'method' => $method,
  40. 'uri' => $_SERVER['REQUEST_URI'] ?? null,
  41. 'ip' => $_SERVER['REMOTE_ADDR'] ?? null,
  42. 'ua' => $_SERVER['HTTP_USER_AGENT'] ?? null,
  43. ]);
  44. if ($rawBody !== '') {
  45. // UWAGA: czasem payload jest duży; możesz obciąć do np. 50k
  46. Logger::debug('Incoming body', [
  47. 'body' => json_decode($rawBody, true) ?? $rawBody
  48. ]);
  49. }
  50. $router->dispatch($method, $path);