add otp swagger

This commit is contained in:
2026-05-11 12:25:33 +03:30
parent 5546b1e7c1
commit 22d8b15000
5 changed files with 39 additions and 8 deletions

View File

@@ -1,11 +1,39 @@
import { NextResponse } from "next/server";
import { NextRequest, NextResponse } from "next/server";
import { openApiSpec } from "@/lib/openapi";
export async function GET() {
return NextResponse.json(openApiSpec, {
function getRequestOrigin(req: NextRequest) {
const forwardedProto = req.headers.get("x-forwarded-proto")?.split(",")[0]?.trim();
const forwardedHost = req.headers.get("x-forwarded-host")?.split(",")[0]?.trim();
const host = forwardedHost ?? req.headers.get("host");
const proto = forwardedProto ?? req.nextUrl.protocol.replace(":", "");
const origin = host ? `${proto}://${host}` : req.nextUrl.origin;
try {
const url = new URL(origin);
if (url.protocol === "http:" || url.protocol === "https:") return url.origin;
} catch {
// Fall through to the same-origin server below.
}
return "/";
}
export async function GET(req: NextRequest) {
return NextResponse.json({
...openApiSpec,
servers: [
{
url: getRequestOrigin(req),
description: "Current request origin",
},
{
url: "/",
description: "Same-origin fallback",
},
],
}, {
headers: {
"Cache-Control": "no-store",
},
});
}