fix: consolidate all chat API calls onto /admin/chat with ?api= param

Nginx intercepts any request to /admin/chat/* sub-routes. Fix by handling
all chat API requests on the same /admin/chat path using query params:
  GET  /admin/chat?api=convs        → conversations list
  GET  /admin/chat?api=msgs&phone=X → messages for a phone
  POST /admin/chat                  → send message

JS fetch URLs updated accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-27 19:48:21 -05:00
co-authored by Claude Sonnet 4.6
parent 4f30ed4447
commit 5bae03e5a3
2 changed files with 10 additions and 7 deletions
+3 -3
View File
@@ -1922,7 +1922,7 @@ let activePhone = '';
async function loadConvs() {
const list = document.getElementById('convList');
try {
const r = await fetch('/admin/chat-convs');
const r = await fetch('/admin/chat?api=convs');
if (!r.ok) {
list.innerHTML = \`<div style="padding:16px;color:#e53e3e;font-size:13px">Error \${r.status} al cargar conversaciones</div>\`;
return;
@@ -1992,7 +1992,7 @@ async function loadMessages(phone) {
msgsDiv.innerHTML = '<div style="text-align:center;padding:20px;color:#a0a8b8">Cargando...</div>';
let data;
try {
const r = await fetch('/admin/chat-msgs?phone=' + encodeURIComponent(phone));
const r = await fetch('/admin/chat?api=msgs&phone=' + encodeURIComponent(phone));
if (!r.ok) {
msgsDiv.innerHTML = \`<div style="text-align:center;padding:20px;color:#e53e3e">Error \${r.status}</div>\`;
return;
@@ -2064,7 +2064,7 @@ async function sendMsg() {
if (!text || !activePhone) return;
document.getElementById('sendBtn').disabled = true;
try {
const r = await fetch('/admin/chat-send', {
const r = await fetch('/admin/chat', {
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({phone:activePhone, text})
+7 -4
View File
@@ -90,10 +90,13 @@ $routes = [
['GET', '/admin/webhook/stream/sse', fn() => DashboardController::streamSse()],
['GET', '/admin/webhook/stream', fn() => DashboardController::stream()],
['GET', '/admin/webhook/raw', fn() => DashboardController::getRaw()],
['GET', '/admin/chat', fn() => DashboardController::chat()],
['GET', '/admin/chat-convs', fn() => DashboardController::chatConversations()],
['GET', '/admin/chat-msgs', fn() => DashboardController::chatMessages()],
['POST', '/admin/chat-send', fn() => DashboardController::chatSend()],
['GET', '/admin/chat', fn() => (function () {
$api = $_GET['api'] ?? '';
if ($api === 'convs') { DashboardController::chatConversations(); return; }
if ($api === 'msgs') { DashboardController::chatMessages(); return; }
DashboardController::chat();
})()],
['POST', '/admin/chat', fn() => DashboardController::chatSend()],
// ─── Páginas legales (requeridas por Meta/WhatsApp Business) ────────────
['GET', '/politicas', fn() => serveHtml('politicas.html')],