search_awesome/routes/api/_query.ts
2022-12-01 19:40:03 +09:00

19 lines
486 B
TypeScript

import { Handlers } from "$fresh/server.ts";
import { searchRepos, getRepos } from "../../api/repo.ts";
export const handler: Handlers = {
async GET(req, _ctx) {
const url = new URL(req.url);
const q = url.searchParams.get("q");
const repos = q != null ? await searchRepos(q, {
limit: 10,
offset: 0
}) : await getRepos();
return new Response(JSON.stringify(repos), {
headers: {
"content-type": "application/json",
},
});
}
}