Skip to content

Commit f12fcc5

Browse files
committed
Add destination api endpoint
1 parent 94f588c commit f12fcc5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/app/api/-/destination/route.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { NextRequest, NextResponse } from "next/server";
2+
import destination from "^/lib/destination";
3+
4+
function assureArrayLength(specs: string[]) {
5+
if (specs.length < 3) {
6+
return specs as [string] | [string, string];
7+
}
8+
throw new Error("Too many specs");
9+
}
10+
11+
export async function GET(req: NextRequest, { params }: { params: {} }) {
12+
const { searchParams } = new URL(req.url);
13+
14+
const specsOrVersions = assureArrayLength(
15+
searchParams.getAll("specs") ?? "",
16+
);
17+
18+
console.log("[api/-/destination] running", specsOrVersions);
19+
20+
const result = await destination(specsOrVersions);
21+
22+
return NextResponse.json(result);
23+
}

0 commit comments

Comments
 (0)