Skip to content

Commit 9ad3578

Browse files
committed
script/serve-public.js: handle all URLs ending in a slash correctly
There is already code to handle the top-level URL correctly. However, URLs like http://localhost:5000/book/ still weren't handled by appending `index.html`. Let's fix this. This is needed because we are _just_ about to add tests to verify that the book redirects at URLs like https://git-scm.com/book/ work. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 605793f commit 9ad3578

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

script/serve-public.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ const mimeTypes = {
2525

2626
const handler = (request, response) => {
2727
const pathname = decodeURIComponent(url.parse(request.url).pathname);
28-
let filename = path.join(basePath, pathname === "/" ? "index.html" : pathname);
28+
let filename = path.join(
29+
basePath,
30+
pathname === "/"
31+
? "index.html"
32+
: pathname.endsWith("/")
33+
? `${pathname}index.html`
34+
: pathname
35+
);
2936

3037
let stats = fs.statSync(filename, { throwIfNoEntry: false });
3138
if (!stats?.isFile() && !filename.match(/\.[A-Za-z0-9]{1,11}$/)) {

0 commit comments

Comments
 (0)