mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-24 16:12:23 +03:00
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import {
|
|
OutboundUrlGuardError,
|
|
parseAndValidateNonMetadataUrl,
|
|
parseAndValidatePublicUrl,
|
|
parseOutboundUrl,
|
|
} from "@/shared/network/outboundUrlGuard";
|
|
import { getProviderValidationGuard } from "@/shared/network/outboundUrlGuardPolicy";
|
|
|
|
function guardProviderNodeBaseUrl(baseUrl: string): void {
|
|
const guard = getProviderValidationGuard();
|
|
if (guard === "none") {
|
|
parseOutboundUrl(baseUrl);
|
|
return;
|
|
}
|
|
if (guard === "block-metadata") {
|
|
parseAndValidateNonMetadataUrl(baseUrl);
|
|
return;
|
|
}
|
|
parseAndValidatePublicUrl(baseUrl);
|
|
}
|
|
|
|
export function validateProviderNodeBaseUrl(baseUrl: string): NextResponse | null {
|
|
try {
|
|
guardProviderNodeBaseUrl(baseUrl);
|
|
return null;
|
|
} catch (error) {
|
|
const message =
|
|
error instanceof OutboundUrlGuardError
|
|
? error.code === "OUTBOUND_URL_INVALID"
|
|
? "Invalid provider base URL format"
|
|
: error.message
|
|
: "Invalid provider base URL";
|
|
return NextResponse.json(
|
|
{
|
|
error: {
|
|
message: "Invalid request",
|
|
details: [{ field: "baseUrl", message }],
|
|
},
|
|
},
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
}
|