Skip to main content
Home

Built and signed on GitHub Actions

It is unknown whether this package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
35%
Published
a year ago (0.1.2)
Package root>server.ts
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 ) ); }, });