fix(admin-web): maintenance page API path mismatches + base proxy route

- 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
This commit is contained in:
saravanakumardb1 2026-03-21 20:37:32 -07:00
parent ce0074d6ee
commit daf1f90706
2 changed files with 42 additions and 3 deletions

View File

@ -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);

View File

@ -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<string, string> = {
'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);
}