aboutsummaryrefslogtreecommitdiff
path: root/source/graphiql/assets.ts
blob: d0848e7e2bdbe4073e606e6c94d1b39dc20eb5ec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// source/graphiql/assets.ts
import css from "./standalone.css" with { type: "text" };
import favicon from "./favicon.svg" with { type: "text" };
import js from "./standalone.js" with { type: "text" };
import { GRAPHIQL_VERSION } from "./version.ts";

const base = `/_graphiql/${GRAPHIQL_VERSION}`;

export const assets: Record<string, { body: string; type: string }> = {
  [`${base}/favicon.svg`]: { body: favicon, type: "image/svg+xml" },
  [`${base}/standalone.css`]: { body: css, type: "text/css; charset=utf-8" },
  [`${base}/standalone.js`]: { body: js, type: "text/javascript; charset=utf-8" }
};

export function serveAsset(request: { url: string }): Response | undefined {
  const { pathname } = new URL(request.url);
  const key = Object.keys(assets).find((path) => pathname.endsWith(path));

  if (!key)
    return;

  return new Response(assets[key].body, {
    headers: {
      "cache-control": "public, max-age=31536000, immutable",
      "content-type": assets[key].type
    }
  });
}