wrong links in directory listings #1

Closed
opened 2025-07-19 02:20:37 -04:00 by maci0 · 5 comments
maci0 commented 2025-07-19 02:20:37 -04:00 (Migrated from github.com)
~/Desktop
❯ ./bash-web-server -d bws/
listening on http://0.0.0.0:8080
serving out of bws/
~/Desktop/bws
❯ find .
.
./foo
./foo/bar.txt
~/Desktop/bws
❯ curl localhost:8080
<h1>Directory Listing</h1>
<h2>Directory: .</h2>
<hr>
<ul>
<li><a href="..">..</a></li>
<li><a href="foo">foo</a></li>
</ul>
<hr>

~/Desktop/bws
❯ curl localhost:8080/foo
<h1>Directory Listing</h1>
<h2>Directory: foo</h2>
<hr>
<ul>
<li><a href="..">..</a></li>
<li><a href="bar.txt">bar.txt</a></li>
</ul>
<hr>

~/Desktop/bws
❯

the link to bar.txt is wrong it should link to foo/bar.txt

``` ~/Desktop ❯ ./bash-web-server -d bws/ listening on http://0.0.0.0:8080 serving out of bws/ ``` ``` ~/Desktop/bws ❯ find . . ./foo ./foo/bar.txt ~/Desktop/bws ❯ curl localhost:8080 <h1>Directory Listing</h1> <h2>Directory: .</h2> <hr> <ul> <li><a href="..">..</a></li> <li><a href="foo">foo</a></li> </ul> <hr> ~/Desktop/bws ❯ curl localhost:8080/foo <h1>Directory Listing</h1> <h2>Directory: foo</h2> <hr> <ul> <li><a href="..">..</a></li> <li><a href="bar.txt">bar.txt</a></li> </ul> <hr> ~/Desktop/bws ❯ ``` the link to bar.txt is wrong it should link to foo/bar.txt
bahamas10 commented 2025-07-19 18:05:06 -04:00 (Migrated from github.com)

What you have makes sense to me - I'm not sure what the issue is?

Are you saying that:

<li><a href="bar.txt">bar.txt</a></li>

should be:

<li><a href="foo/bar.txt">bar.txt</a></li>

Because if so, that is incorrect - your browser treats links as relative when they don't start with a protocol or a / so having it link to just the basename of the file is correct.

What you have makes sense to me - I'm not sure what the issue is? Are you saying that: ``` <li><a href="bar.txt">bar.txt</a></li> ``` should be: ``` <li><a href="foo/bar.txt">bar.txt</a></li> ``` Because if so, that is incorrect - your browser treats links as relative when they don't start with a protocol or a `/` so having it link to just the basename of the file *is* correct.
maci0 commented 2025-07-20 01:01:56 -04:00 (Migrated from github.com)

what i'm saying the current code only works for one level of directories. the moment you have multiple levels of nesting it won't work.

what i'm saying the current code only works for one level of directories. the moment you have multiple levels of nesting it won't work.
maci0 commented 2025-07-20 01:06:04 -04:00 (Migrated from github.com)

ok.. i think i found out why...

currently when you click a directory it will redirect to /foo and not /foo/ . if i manually change the address in the address bar it works

ok.. i think i found out why... currently when you click a directory it will redirect to /foo and not /foo/ . if i manually change the address in the address bar it works
maci0 commented 2025-07-20 01:15:16 -04:00 (Migrated from github.com)
https://github.com/bahamas10/bash-web-server/pull/2
bahamas10 commented 2025-07-20 02:01:34 -04:00 (Migrated from github.com)

closing this as #2 was merged - thank you!

closing this as #2 was merged - thank you!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mike/bash-web-server#1
No description provided.