diff options
| author | netop://ウィビ <paul@webb.page> | 2026-10-21 16:47:38 -0700 |
|---|---|---|
| committer | netop://ウィビ <paul@webb.page> | 2026-10-21 16:47:38 -0700 |
| commit | 389ad1349c4ff245a3466a2e361c1cd1dd11d2ba (patch) | |
| tree | 0ad0638f60ab0a77c7a095e96b472312ab39f83b /source/graphiql/assets.ts | |
| parent | bbcbb02ef64d094f0f13de22ae135eeba1ff4c5d (diff) | |
| download | gq-primary.tar.gz gq-primary.zip | |
- inlined vendored dependencies from npm
- makes this module work in Ende
Diffstat (limited to '')
| -rw-r--r-- | source/graphiql/assets.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/source/graphiql/assets.ts b/source/graphiql/assets.ts new file mode 100644 index 0000000..d0848e7 --- /dev/null +++ b/source/graphiql/assets.ts @@ -0,0 +1,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 + } + }); +} |