From daf1f907061dc85415601d510f4d46d420d490d5 Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Sat, 21 Mar 2026 20:37:32 -0700 Subject: [PATCH] fix(admin-web): maintenance page API path mismatches + base proxy route MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - maintenance page: 'status' → 'full' (GET /settings/maintenance/full) - maintenance page: 'mode' POST → '' PUT (PUT /settings/maintenance) - Add maintenance base route.ts for root-level GET/PUT proxy --- .../src/app/(dashboard)/maintenance/page.tsx | 6 +-- .../src/app/api/maintenance/route.ts | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 dashboards/admin-web/src/app/api/maintenance/route.ts diff --git a/dashboards/admin-web/src/app/(dashboard)/maintenance/page.tsx b/dashboards/admin-web/src/app/(dashboard)/maintenance/page.tsx index dd51e0ae..335dc174 100644 --- a/dashboards/admin-web/src/app/(dashboard)/maintenance/page.tsx +++ b/dashboards/admin-web/src/app/(dashboard)/maintenance/page.tsx @@ -59,7 +59,7 @@ export default function MaintenancePage() { const loadData = useCallback(async () => { setLoading(true); - const data = await apiFetch('status'); + const data = await apiFetch('full'); if (data?.mode) { setStatus(data); setNewMode(data.mode); @@ -74,8 +74,8 @@ export default function MaintenancePage() { async function handleSave() { setSaving(true); - await apiFetch('mode', { - method: 'POST', + await apiFetch('', { + method: 'PUT', body: JSON.stringify({ mode: newMode, message: newMessage || undefined }), }); setSaving(false); diff --git a/dashboards/admin-web/src/app/api/maintenance/route.ts b/dashboards/admin-web/src/app/api/maintenance/route.ts new file mode 100644 index 00000000..8d58be08 --- /dev/null +++ b/dashboards/admin-web/src/app/api/maintenance/route.ts @@ -0,0 +1,39 @@ +/** + * Maintenance base route — handles GET /api/maintenance and PUT /api/maintenance. + * Maps to platform-service GET /api/settings/maintenance and PUT /api/settings/maintenance. + */ + +import { NextRequest, NextResponse } from 'next/server'; +import { getCurrentUserFromRequest } from '@/lib/auth-server'; +import { logError } from '@/lib/logger'; + +const PLATFORM_URL = process.env.PLATFORM_SERVICE_URL || 'http://localhost:4003'; + +async function proxyBase(req: NextRequest) { + try { + const caller = await getCurrentUserFromRequest(req); + if (!caller) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); + const qs = new URL(req.url).search; + const headers: Record = { + 'Content-Type': 'application/json', + 'x-request-id': req.headers.get('x-request-id') || crypto.randomUUID(), + 'x-user-id': caller.id, + 'x-product-id': req.headers.get('x-product-id') || process.env.PRODUCT_ID || 'lysnrai', + }; + const fetchOptions: RequestInit = { method: req.method, headers }; + if (req.method !== 'GET' && req.method !== 'HEAD') fetchOptions.body = await req.text(); + const res = await fetch(`${PLATFORM_URL}/api/settings/maintenance${qs}`, fetchOptions); + const data = await res.json().catch(() => null); + return NextResponse.json(data ?? { error: res.statusText }, { status: res.status }); + } catch (error) { + logError('Maintenance base proxy error', error); + return NextResponse.json({ error: 'Service unavailable' }, { status: 502 }); + } +} + +export async function GET(req: NextRequest) { + return proxyBase(req); +} +export async function PUT(req: NextRequest) { + return proxyBase(req); +}