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:
parent
ce0074d6ee
commit
daf1f90706
@ -59,7 +59,7 @@ export default function MaintenancePage() {
|
|||||||
|
|
||||||
const loadData = useCallback(async () => {
|
const loadData = useCallback(async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const data = await apiFetch('status');
|
const data = await apiFetch('full');
|
||||||
if (data?.mode) {
|
if (data?.mode) {
|
||||||
setStatus(data);
|
setStatus(data);
|
||||||
setNewMode(data.mode);
|
setNewMode(data.mode);
|
||||||
@ -74,8 +74,8 @@ export default function MaintenancePage() {
|
|||||||
|
|
||||||
async function handleSave() {
|
async function handleSave() {
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
await apiFetch('mode', {
|
await apiFetch('', {
|
||||||
method: 'POST',
|
method: 'PUT',
|
||||||
body: JSON.stringify({ mode: newMode, message: newMessage || undefined }),
|
body: JSON.stringify({ mode: newMode, message: newMessage || undefined }),
|
||||||
});
|
});
|
||||||
setSaving(false);
|
setSaving(false);
|
||||||
|
|||||||
39
dashboards/admin-web/src/app/api/maintenance/route.ts
Normal file
39
dashboards/admin-web/src/app/api/maintenance/route.ts
Normal 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);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user