Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
albnnc/storybookIt is unknown whether this package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers




JSR Score
35%
Published
a year ago (0.1.2)
import * as fs from "jsr:@std/fs@^1.0.1"; import * as fileServer from "jsr:/@std/http@^1.0.3/file-server"; import * as path from "jsr:@std/path@^0.225.2"; const currentDir = path.fromFileUrl(import.meta.resolve("./")); const metaGlob = path.join(currentDir, "./stories/*/meta.json"); const indexHtmlFilePath = path.join(currentDir, "./index.html"); const urlRoot = Deno.env.get("URL_ROOT") || undefined; Deno.serve({ handler: async (req) => { const url = new URL(req.url); const pathname = urlRoot ? url.pathname.replace(urlRoot, "").replace(/\/+/, "/") : url.pathname; if (pathname === "/api/stories") { const metas: unknown[] = []; for await (const v of fs.expandGlob(metaGlob)) { metas.push(await Deno.readTextFile(v.path).then(JSON.parse)); } return new Response(JSON.stringify(metas)); } return ( fileServer .serveDir(req, { fsRoot: currentDir, urlRoot, quiet: true, }) .then((v) => v.status === 404 ? fileServer.serveFile(req, indexHtmlFilePath) : v ) ); }, });