31 lines
1001 B
TypeScript
31 lines
1001 B
TypeScript
import { NextResponse } from "next/server";
|
|
import {
|
|
MAX_CONDUIT_FEATURES,
|
|
MAX_MAP_FEATURE_IDS,
|
|
createMapFeatureWfsUrl,
|
|
normalizeMapFeatureCollection,
|
|
parseMapFeatureQuery
|
|
} from "@/features/workbench/map/map-feature-query";
|
|
|
|
export async function POST(request: Request) {
|
|
const parsed = parseMapFeatureQuery(await request.json().catch(() => null));
|
|
if (!parsed.ok) {
|
|
return NextResponse.json({ code: parsed.code }, { status: parsed.status });
|
|
}
|
|
|
|
try {
|
|
const response = await fetch(createMapFeatureWfsUrl(parsed.value), {
|
|
cache: "no-store",
|
|
signal: AbortSignal.timeout(8_000)
|
|
});
|
|
const collection = normalizeMapFeatureCollection(
|
|
await response.json(),
|
|
parsed.value.featureIds ? MAX_MAP_FEATURE_IDS : MAX_CONDUIT_FEATURES
|
|
);
|
|
if (!response.ok || !collection) throw new Error("Invalid WFS response");
|
|
return NextResponse.json(collection);
|
|
} catch {
|
|
return NextResponse.json({ code: "WFS_UNAVAILABLE" }, { status: 502 });
|
|
}
|
|
}
|