MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / loader

Function loader

app/routes/actions/getPreview.$url.ts:5–41  ·  view source on GitHub ↗
({ params })

Source from the content-addressed store, hash-verified

3import { getUriPreview } from "~/services/uriPreview.server";
4
5export const loader: LoaderFunction = async ({ params }) => {
6 try {
7 invariant(params.url, "expected params.url");
8
9 const decoded = decodeURIComponent(params.url);
10
11 const earlyReturn = earlyRespondIfHomepagePreviewUri(decoded);
12
13 if (earlyReturn) {
14 return new Response(JSON.stringify(earlyReturn), {
15 headers: {
16 "Content-Type": "application/json; charset=utf-8",
17 "Cache-Control": "public, max-age=3600",
18 },
19 });
20 }
21
22 const result = await getUriPreview(decoded);
23
24 return new Response(JSON.stringify(result), {
25 headers: {
26 "Content-Type": "application/json; charset=utf-8",
27 "Cache-Control": "public, max-age=3600",
28 },
29 });
30 } catch {
31 return new Response(
32 JSON.stringify({ error: "Unable to preview this URL" }),
33 {
34 headers: {
35 "Content-Type": "application/json; charset=utf-8",
36 "Cache-Control": "public, max-age=3600",
37 },
38 }
39 );
40 }
41};
42
43function earlyRespondIfHomepagePreviewUri(uri: string) {
44 if (uri === "https://www.theonion.com/") {

Callers

nothing calls this directly

Calls 2

getUriPreviewFunction · 0.90

Tested by

no test coverage detected