Fix Telegram webhook route: Move before generic OPTIONS route

This commit is contained in:
mwpn
2026-01-26 09:49:23 +07:00
parent e15ff0baf8
commit f34e7015ec

View File

@@ -52,11 +52,6 @@ $app->add(function (Request $request, $handler) {
->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS'); ->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
}); });
// Handle OPTIONS request
$app->options('/{routes:.+}', function (Request $request, Response $response) {
return $response;
});
// Add error middleware // Add error middleware
$app->addErrorMiddleware(true, true, true); $app->addErrorMiddleware(true, true, true);
@@ -215,10 +210,17 @@ $app->get('/fast/mandiri/{tanggal}', [$fastController, 'mandiri']);
$app->post('/site/verify_bri', [$siteController, 'verifyBri']); $app->post('/site/verify_bri', [$siteController, 'verifyBri']);
$app->post('/site/approve/{id_trx}', [$siteController, 'approve']); $app->post('/site/approve/{id_trx}', [$siteController, 'approve']);
// Telegram Bot Routes // Telegram Bot Routes (diletakkan sebelum route generic untuk menghindari konflik)
$telegramBotController = new \App\Controllers\TelegramBotController(); $telegramBotController = new \App\Controllers\TelegramBotController();
$app->post('/telegram/webhook', [$telegramBotController, 'webhook']); $app->post('/telegram/webhook', [$telegramBotController, 'webhook']);
// Note: OPTIONS request sudah ditangani oleh route generic di line 56 $app->options('/telegram/webhook', function (Request $request, Response $response) {
return $response->withStatus(200);
});
// Handle OPTIONS request untuk route lainnya (harus setelah route spesifik)
$app->options('/{routes:.+}', function (Request $request, Response $response) {
return $response;
});
// Run app // Run app
$app->run(); $app->run();