g1t/apps/web/app/routes/search-json.ts
Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Search across all of g1t, Explore, and a command palette | 1 | /** |
| 2 | * What the command palette shows as someone types: a few repositories, | |
| 3 | * issues, pull requests and people, as the viewer may see them. Signed out, | |
| 4 | * public ones only. | |
| 5 | */ | |
| 6 | import type { Route } from "./+types/search-json"; | |
| 7 | import { search } from "../lib/services.server"; | |
| 8 | import { getViewer } from "../lib/session.server"; | |
| 9 | ||
| 10 | export async function loader({ request, context }: Route.LoaderArgs) { | |
| 11 | const q = (new URL(request.url).searchParams.get("q") ?? "").trim().slice(0, 256); | |
| 12 | const headers = { "cache-control": "no-store" }; | |
| 13 | if (q.length < 2) return Response.json({ q, hits: [] }, { headers }); | |
| 14 | try { | |
| 15 | return Response.json({ q, hits: await search.suggest(getViewer(context), q) }, { headers }); | |
| 16 | } catch { | |
| 17 | return Response.json({ q, hits: [] }, { headers }); | |
| 18 | } | |
| 19 | } |