diff --git a/README.md b/README.md index 50c2004..8ea156b 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,9 @@ const ipx = createIPX({ httpStorage: ipxHttpStorage({ domains: ["picsum.photos"] }), }); -const app = createApp().use("/", createIPXH3Handler(ipx)); +const base = '/' + +const app = createApp().use(base, createIPXH3Handler(ipx, { base })); listen(toNodeListener(app)); ``` diff --git a/src/server.ts b/src/server.ts index a1e7fef..68a0526 100644 --- a/src/server.ts +++ b/src/server.ts @@ -22,11 +22,11 @@ import { IPX } from "./ipx"; const MODIFIER_SEP = /[&,]/g; const MODIFIER_VAL_SEP = /[:=_]/; -export function createIPXH3Handler(ipx: IPX) { +export function createIPXH3Handler(ipx: IPX, options = { base: "/" }) { const _handler = async (event: H3Event) => { // Parse URL const [modifiersString = "", ...idSegments] = event.path - .slice(1 /* leading slash */) + .replace(options.base, "") .split("/"); const id = safeString(decode(idSegments.join("/"))); @@ -47,7 +47,7 @@ export function createIPXH3Handler(ipx: IPX) { }); } - // Contruct modifiers + // Construct modifiers const modifiers: Record = Object.create(null); // Read modifiers from first segment