import type { Server } from "bun"; import { contentResponse } from "./content/routes"; import home from "./index.html"; import m0 from "./mockups/01-editorial/index.html"; import m1 from "./mockups/02-vertical-story/index.html"; import m2 from "./mockups/03-transit-map/index.html"; import m3 from "./mockups/04-greek-frieze/index.html"; import m4 from "./mockups/05-score/index.html"; import m5 from "./mockups/06-constellation/index.html"; import m6 from "./mockups/07-sea-voyage/index.html"; import m7 from "./mockups/08-chart-logline/index.html"; import m8 from "./mockups/09-chart-transit/index.html"; import m9 from "./mockups/10-chart-scroll/index.html"; import m10 from "./mockups/11-chart-atlas/index.html"; import m11 from "./mockups/12-vellum-atlas/index.html"; import m12 from "./mockups/13-curtain-call/index.html"; import m13 from "./mockups/14-voyage-panel/index.html"; import m14 from "./mockups/15-voyage-look2/index.html"; import m15 from "./mockups/16-voyage-readable/index.html"; import m16 from "./mockups/17-voyage-real/index.html"; export interface ServerOptions { /** Folder with the real content (audio, lyrics, Homer); defaults to CONTENT_DIR. See spec 003. */ contentDir?: string; } export function startServer(port: number, opts: ServerOptions = {}): Server { const contentDir = "contentDir" in opts ? opts.contentDir : process.env.CONTENT_DIR; return Bun.serve({ port, routes: { "/": home, "/mockups/01-editorial/": m0, "/mockups/01-editorial": Response.redirect("/mockups/01-editorial/", 302), "/mockups/02-vertical-story/": m1, "/mockups/02-vertical-story": Response.redirect("/mockups/02-vertical-story/", 302), "/mockups/03-transit-map/": m2, "/mockups/03-transit-map": Response.redirect("/mockups/03-transit-map/", 302), "/mockups/04-greek-frieze/": m3, "/mockups/04-greek-frieze": Response.redirect("/mockups/04-greek-frieze/", 302), "/mockups/05-score/": m4, "/mockups/05-score": Response.redirect("/mockups/05-score/", 302), "/mockups/06-constellation/": m5, "/mockups/06-constellation": Response.redirect("/mockups/06-constellation/", 302), "/mockups/07-sea-voyage/": m6, "/mockups/07-sea-voyage": Response.redirect("/mockups/07-sea-voyage/", 302), "/mockups/08-chart-logline/": m7, "/mockups/08-chart-logline": Response.redirect("/mockups/08-chart-logline/", 302), "/mockups/09-chart-transit/": m8, "/mockups/09-chart-transit": Response.redirect("/mockups/09-chart-transit/", 302), "/mockups/10-chart-scroll/": m9, "/mockups/10-chart-scroll": Response.redirect("/mockups/10-chart-scroll/", 302), "/mockups/11-chart-atlas/": m10, "/mockups/11-chart-atlas": Response.redirect("/mockups/11-chart-atlas/", 302), "/mockups/12-vellum-atlas/": m11, "/mockups/12-vellum-atlas": Response.redirect("/mockups/12-vellum-atlas/", 302), "/mockups/13-curtain-call/": m12, "/mockups/13-curtain-call": Response.redirect("/mockups/13-curtain-call/", 302), "/mockups/14-voyage-panel/": m13, "/mockups/14-voyage-panel": Response.redirect("/mockups/14-voyage-panel/", 302), "/mockups/15-voyage-look2/": m14, "/mockups/15-voyage-look2": Response.redirect("/mockups/15-voyage-look2/", 302), "/mockups/16-voyage-readable/": m15, "/mockups/16-voyage-readable": Response.redirect("/mockups/16-voyage-readable/", 302), "/mockups/17-voyage-real/": m16, "/mockups/17-voyage-real": Response.redirect("/mockups/17-voyage-real/", 302), }, development: process.env.NODE_ENV !== "production", fetch(req) { return contentResponse(req, contentDir) ?? new Response("Not found", { status: 404 }); }, }); } if (import.meta.main) { const server = startServer(Number(process.env.PORT ?? 3000)); console.log(`Listening on ${server.url}`); }