lwsjs / local-web-server

A lean, modular web server for rapid full-stack development.
MIT License
1.21k stars 85 forks source link

Missing trailing slash #56

Closed HernanZh closed 5 years ago

HernanZh commented 7 years ago

Hello, I like using this package as a simple server inside my projects folder and as such I always use the server's filetree to navigate to the project I like to load in the browser. However, I recently updated and now there is always a missing slash at the end.

For example when I click on "project1" folder, it loads "localhost:8000/project1" instead of "localhost:8000/project1/". This results in 404 errors for all javascript and css files.

75lb commented 7 years ago

i've come across this issue before, it's an issue in the underlying module supplying the directory-browsing feature.. will look into it, thanks.

HernanZh commented 7 years ago

Oops, I forgot about this issue. Either way, thanks for this useful tool. I hope you figure out this issue.

75lb commented 7 years ago

this is resolved in v2 which is in progress and available for preview.. any feedback welcome.

HernanZh commented 7 years ago

Hm, annoyingly enough, one of the node modules is giving me an error, requiring node v7.6+ --> https://github.com/koajs/bodyparser/issues/66

I'll have to check this later

75lb commented 7 years ago

yeah, sorry about that - koa is node v7.6 at the minimum these days (for async/await support).

HernanZh commented 7 years ago

Alright, I installed the latest node. Seems to work! Forcing the new node version on other users could be problematic though, but that's up to you...

75lb commented 7 years ago

glad it works! I didn't choose to force the latest node on users - this constraint was forced upon us by the Koa project unfortunately. I don't agree with it but don't have much choice.

75lb commented 7 years ago

fixed and released in v2.0.0

sergebat commented 5 years ago

I'd like to report that this issue reappeared on the version 3.0 (reproduced on Win 10, 3.0.4). 2.0 works fine for me.

Fragment of listing html that I see (just installed local-web-server into empty folder, created test subfolder, started the server and navigated to localhost:8000):

    <div id="wrapper">
      <h1><a href="http://127.0.0.1:8000/">~</a> / </h1>
      <ul id="files" class="view-tiles"><li><a href="http://127.0.0.1:8000/node_modules" class="icon icon-directory" title="node_modules"><span class="name">node_modules</span><span class="size"></span><span class="date">2019-7-15 2:59:38 PM</span></a></li>
<li><a href="http://127.0.0.1:8000/test" class="icon icon-directory" title="test"><span class="name">test</span><span class="size"></span><span class="date">2019-7-15 3:00:32 PM</span></a></li>
<li><a href="http://127.0.0.1:8000/package-lock.json" class="icon icon icon-json icon-application-json" title="package-lock.json"><span class="name">package-lock.json</span><span class="size">56802</span><span class="date">2019-7-15 2:59:38 PM</span></a></li></ul>
    </div>
75lb commented 5 years ago

Hmm, i can't reproduce this on macOS and in it theory it should not behave any differently on Windows.. I will try and reproduce it on Windows later.

75lb commented 5 years ago

I can't reproduce on Windows either. I installed local-web-server v3.0.4 on Windows 10 (version 1809), created a folder, a sub-folder and some files and could navigate the sub-folders without issue.

Could you post a specific, failing reproduction case please which I can use to see and debug the issue.

sergebat commented 5 years ago

and could navigate the sub-folders without issue

Let me note that basic navigation indeed works. The problem is that it opens the folder "localhost:8000/project1" instead of "localhost:8000/project1/" as stated in the original issue. It breaks relative urls for assets referenced by index.html in localhost:8000/project1.

If you still cannot reproduce it, I guess I can indeed commit the repo, but the only thing I did was to:

Open 127.0.0.1:8000 and observe no trailing slash for the projects. npm install local-web-server@2 fixes the issue for me.

75lb commented 5 years ago

It breaks relative urls for assets referenced by index.html in localhost:8000/project1.

I can't reproduce this, relative links work fine for me. I'm sorry to keep asking but I need a specific reproduction case which i can run and see failing. Please post your index.html code which contains a relative URL link which fails.

Locally, I created an index.html which displays images loaded via relative URLs and everything loads correctly.

sergebat commented 5 years ago

Sure:

Opened localhost:8000 in chrome and saved resulting listing as: https://github.com/sergebat/lws-reproduce-56/blob/06c5a0cd919201855f71e695afbeaf2901dd7e17/listing%20directory%20_.html#L347

Let me try the same on osx/ubuntu a bit later.

Can you please attach listing you get when running the same in your environment? Thanks!

For the record: Microsoft Windows [Version 10.0.18362.239]

75lb commented 5 years ago

Great, thanks for that. Yes, now I see what you mean. It's an issue on mac too.

It looks like I will need to fork and patch serve-index again (which was how I solved this back in 2017).

Will fix ASAP.

75lb commented 5 years ago

Fixed and released in lws-index v1.0.5. Please reinstall local-web-server to pick up the change.

If you find any more issues, please let me know. 👍