Skip to content

Commit

Permalink
fix: handle lack of bases
Browse files Browse the repository at this point in the history
  • Loading branch information
mxdvl committed Jun 9, 2023
1 parent e120fb9 commit 6e9c32b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ export const create_handler = (
): Handler => ((req) => {
const url = new URL(req.url);

if (url.pathname.startsWith(normalise("/" + base))) {
return serveDir(req, { fsRoot: out_dir, urlRoot: base });
const normalised_base = normalise("/" + base);

if (url.pathname.startsWith(normalised_base)) {
return serveDir(req, {
fsRoot: out_dir,
urlRoot: normalised_base.slice(1),
});
} else {
return Response.redirect(
new URL(normalise(base + url.pathname), url.origin),
Expand Down

0 comments on commit 6e9c32b

Please sign in to comment.