| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- declare(strict_types=1);
- header('X-EKSRelay: hit');
- file_put_contents(__DIR__ . '/../logs/_probe.txt', "probe " . date('c') . "\n", FILE_APPEND);
- /**
- * EKSRelay – single entry point.
- *
- * Run: php -S 0.0.0.0:8080 -t public
- */
- require_once __DIR__ . '/../vendor/autoload.php';
- use EKSRelay\Core\Env;
- use EKSRelay\Core\Logger;
- use EKSRelay\Core\Router;
- use EKSRelay\Handlers\ChatwootWebhookHandler;
- use EKSRelay\Handlers\NewTicketHandler;
- use EKSRelay\Handlers\WooToolsHandler;
- // ── Bootstrap ──────────────────────────────────────────────────────
- Env::load(__DIR__ . '/../.env');
- Logger::init();
- // ── Routes ─────────────────────────────────────────────────────────
- $router = new Router();
- // Chatwoot webhook
- $router->post('/webhooks/chatwoot', [ChatwootWebhookHandler::class, 'handle']);
- // Tools (called by Flowise or external)
- $router->post('/tools/new_ticket', [NewTicketHandler::class, 'handle']);
- $router->post('/tools/get_order_data', [WooToolsHandler::class, 'getOrderData']);
- $router->post('/tools/get_product_data', [WooToolsHandler::class, 'getProductData']);
- $router->post('/tools/get_shipping_data', [WooToolsHandler::class, 'getShippingData']);
- $router->post('/tools/get_payment_methods', [WooToolsHandler::class, 'getPaymentMethods']);
- $router->post('/tools/get_product_compatibility', [WooToolsHandler::class, 'getProductCompatibility']);
- $router->post('/tools/get_car_data', [WooToolsHandler::class, 'getCarData']);
- // ── Dispatch ───────────────────────────────────────────────────────
- $method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
- $path = $_GET['__path']
- ?? (parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/');
- $path = '/' . trim((string)$path, '/');
- $rawBody = file_get_contents('php://input') ?: '';
- Logger::info('Incoming request', [
- 'method' => $method,
- 'uri' => $_SERVER['REQUEST_URI'] ?? null,
- 'ip' => $_SERVER['REMOTE_ADDR'] ?? null,
- 'ua' => $_SERVER['HTTP_USER_AGENT'] ?? null,
- ]);
- if ($rawBody !== '') {
- // UWAGA: czasem payload jest duży; możesz obciąć do np. 50k
- Logger::debug('Incoming body', [
- 'body' => json_decode($rawBody, true) ?? $rawBody
- ]);
- }
- $router->dispatch($method, $path);
|