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:
co-authored by
Claude Sonnet 4.6
parent
4f30ed4447
commit
5bae03e5a3
@@ -1922,7 +1922,7 @@ let activePhone = '';
|
|||||||
async function loadConvs() {
|
async function loadConvs() {
|
||||||
const list = document.getElementById('convList');
|
const list = document.getElementById('convList');
|
||||||
try {
|
try {
|
||||||
const r = await fetch('/admin/chat-convs');
|
const r = await fetch('/admin/chat?api=convs');
|
||||||
if (!r.ok) {
|
if (!r.ok) {
|
||||||
list.innerHTML = \`<div style="padding:16px;color:#e53e3e;font-size:13px">Error \${r.status} al cargar conversaciones</div>\`;
|
list.innerHTML = \`<div style="padding:16px;color:#e53e3e;font-size:13px">Error \${r.status} al cargar conversaciones</div>\`;
|
||||||
return;
|
return;
|
||||||
@@ -1992,7 +1992,7 @@ async function loadMessages(phone) {
|
|||||||
msgsDiv.innerHTML = '<div style="text-align:center;padding:20px;color:#a0a8b8">Cargando...</div>';
|
msgsDiv.innerHTML = '<div style="text-align:center;padding:20px;color:#a0a8b8">Cargando...</div>';
|
||||||
let data;
|
let data;
|
||||||
try {
|
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) {
|
if (!r.ok) {
|
||||||
msgsDiv.innerHTML = \`<div style="text-align:center;padding:20px;color:#e53e3e">Error \${r.status}</div>\`;
|
msgsDiv.innerHTML = \`<div style="text-align:center;padding:20px;color:#e53e3e">Error \${r.status}</div>\`;
|
||||||
return;
|
return;
|
||||||
@@ -2064,7 +2064,7 @@ async function sendMsg() {
|
|||||||
if (!text || !activePhone) return;
|
if (!text || !activePhone) return;
|
||||||
document.getElementById('sendBtn').disabled = true;
|
document.getElementById('sendBtn').disabled = true;
|
||||||
try {
|
try {
|
||||||
const r = await fetch('/admin/chat-send', {
|
const r = await fetch('/admin/chat', {
|
||||||
method:'POST',
|
method:'POST',
|
||||||
headers:{'Content-Type':'application/json'},
|
headers:{'Content-Type':'application/json'},
|
||||||
body:JSON.stringify({phone:activePhone, text})
|
body:JSON.stringify({phone:activePhone, text})
|
||||||
|
|||||||
+7
-4
@@ -90,10 +90,13 @@ $routes = [
|
|||||||
['GET', '/admin/webhook/stream/sse', fn() => DashboardController::streamSse()],
|
['GET', '/admin/webhook/stream/sse', fn() => DashboardController::streamSse()],
|
||||||
['GET', '/admin/webhook/stream', fn() => DashboardController::stream()],
|
['GET', '/admin/webhook/stream', fn() => DashboardController::stream()],
|
||||||
['GET', '/admin/webhook/raw', fn() => DashboardController::getRaw()],
|
['GET', '/admin/webhook/raw', fn() => DashboardController::getRaw()],
|
||||||
['GET', '/admin/chat', fn() => DashboardController::chat()],
|
['GET', '/admin/chat', fn() => (function () {
|
||||||
['GET', '/admin/chat-convs', fn() => DashboardController::chatConversations()],
|
$api = $_GET['api'] ?? '';
|
||||||
['GET', '/admin/chat-msgs', fn() => DashboardController::chatMessages()],
|
if ($api === 'convs') { DashboardController::chatConversations(); return; }
|
||||||
['POST', '/admin/chat-send', fn() => DashboardController::chatSend()],
|
if ($api === 'msgs') { DashboardController::chatMessages(); return; }
|
||||||
|
DashboardController::chat();
|
||||||
|
})()],
|
||||||
|
['POST', '/admin/chat', fn() => DashboardController::chatSend()],
|
||||||
|
|
||||||
// ─── Páginas legales (requeridas por Meta/WhatsApp Business) ────────────
|
// ─── Páginas legales (requeridas por Meta/WhatsApp Business) ────────────
|
||||||
['GET', '/politicas', fn() => serveHtml('politicas.html')],
|
['GET', '/politicas', fn() => serveHtml('politicas.html')],
|
||||||
|
|||||||
Reference in New Issue
Block a user