babashka / http-server

Serve static assets
MIT License
75 stars 8 forks source link

Lacking '/' at the end of links to directories. #13

Closed KDr2 closed 2 months ago

KDr2 commented 2 months ago

I have a directory:

root
  |- subdir1
  |- subdir2
       |- index.html (refers to style.css with path "style.css")
       |- style.css    

When I start a server with root as its directory and visit it in the browser, the links to the subdirectories are like <a href="http://localhost:8090/subdir2">subdir2/</a>. (Note: there's an ending slash in the text but not in the link.)

When I go to http://localhost:8090/subdir2, I actually visit subdir2/index.html, but due to there being no ending slash in the URL, the browser thinks the ULR of the CSS file would be http://localhost:8090/style.css.

To fix this relative path error, we should append a slash to its link if an item in the list is a directory.

KDr2 commented 2 months ago

And another flaw, the slash(/) is encoded as %2F in the link, though it is right, it's kind of abnormal and ugly -- I think we'd better keep slashes as slashes in URLs.

borkdude commented 2 months ago

PR welcome