search_awesome/routes/api/_query.ts

19 lines
486 B
TypeScript
Raw Permalink Normal View History

2022-12-01 19:40:03 +09:00
import { Handlers } from "$fresh/server.ts";
import { searchRepos, getRepos } from "../../api/repo.ts";
2022-11-29 01:52:44 +09:00
2022-12-01 19:40:03 +09:00
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",
},
});
}
}