Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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));
```
Expand Down
6 changes: 3 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")));
Expand All @@ -47,7 +47,7 @@ export function createIPXH3Handler(ipx: IPX) {
});
}

// Contruct modifiers
// Construct modifiers
const modifiers: Record<string, string> = Object.create(null);

// Read modifiers from first segment
Expand Down