examples/live-notes Public
// The Worker's routes, kept apart from index.ts so they can be tested without the runtime.export type Route = | { kind: "note"; id: string } | { kind: "socket"; id: string } | { kind: "snapshots"; id: string } | { kind: "snapshot"; id: string; version: number } | null;// Note ids are what people put in a link: letters, digits, dashes and underscores.const NOTE = /^\/notes\/([A-Za-z0-9_-]{1,64})(?:\/(ws|snapshots)(?:\/([1-9][0-9]{0,11}))?)?$/;export function route(pathname: string): Route { const m = NOTE.exec(pathname); if (!m) return null; const [, id, part, version] = m; if (!part) return { kind: "note", id }; if (part === "ws") return version ? null : { kind: "socket", id }; return version ? { kind: "snapshot", id, version: Number(version) } : { kind: "snapshots", id };}