feat(parcel-sync): eTerra health check + maintenance detection
- New eterra-health.ts service: pings eTerra periodically (3min), detects maintenance (503, keywords), tracks consecutive failures - New /api/eterra/health endpoint for explicit health queries - Session route blocks login when eTerra is in maintenance (503 response) - GET /api/eterra/session now includes eterraAvailable/eterraMaintenance - ConnectionPill shows amber 'Mentenanță' state with AlertTriangle icon instead of confusing red error when eTerra is down - Auto-connect skips when maintenance detected, retries when back online - 30s session poll auto-detects recovery and re-enables auto-connect
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* GET /api/eterra/health — eTerra platform availability check.
|
||||
*
|
||||
* Returns health status without requiring authentication.
|
||||
* Triggers a fresh check if cached result is stale.
|
||||
*
|
||||
* POST /api/eterra/health — force an immediate fresh check.
|
||||
*/
|
||||
|
||||
import { NextResponse } from "next/server";
|
||||
import {
|
||||
getEterraHealth,
|
||||
checkEterraHealthNow,
|
||||
} from "@/modules/parcel-sync/services/eterra-health";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET() {
|
||||
const health = getEterraHealth();
|
||||
return NextResponse.json(health);
|
||||
}
|
||||
|
||||
export async function POST() {
|
||||
const health = await checkEterraHealthNow();
|
||||
return NextResponse.json(health);
|
||||
}
|
||||
@@ -7,16 +7,24 @@ import {
|
||||
getSessionCredentials,
|
||||
getSessionStatus,
|
||||
} from "@/modules/parcel-sync/services/session-store";
|
||||
import { getEterraHealth } from "@/modules/parcel-sync/services/eterra-health";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
/**
|
||||
* GET /api/eterra/session — returns current server-side session status.
|
||||
* Any client can call this to check if eTerra is connected.
|
||||
* GET /api/eterra/session — returns current server-side session status
|
||||
* enriched with eTerra platform health info.
|
||||
*/
|
||||
export async function GET() {
|
||||
return NextResponse.json(getSessionStatus());
|
||||
const status = getSessionStatus();
|
||||
const health = getEterraHealth();
|
||||
return NextResponse.json({
|
||||
...status,
|
||||
eterraAvailable: health.available,
|
||||
eterraMaintenance: health.maintenance,
|
||||
eterraHealthMessage: health.message,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,6 +78,19 @@ export async function POST(req: Request) {
|
||||
);
|
||||
}
|
||||
|
||||
// Block login when eTerra is in maintenance
|
||||
const health = getEterraHealth();
|
||||
if (!health.available && health.maintenance) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error:
|
||||
"eTerra este în mentenanță — conectarea este dezactivată temporar",
|
||||
maintenance: true,
|
||||
},
|
||||
{ status: 503 },
|
||||
);
|
||||
}
|
||||
|
||||
// Check if already connected with same credentials
|
||||
const existing = getSessionCredentials();
|
||||
if (existing && existing.username === username) {
|
||||
|
||||
Reference in New Issue
Block a user