Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folders are not redirected if missing a slash at the end #130

Open
Maia-Everett opened this issue Jun 22, 2018 · 4 comments
Open

Folders are not redirected if missing a slash at the end #130

Maia-Everett opened this issue Jun 22, 2018 · 4 comments

Comments

@Maia-Everett
Copy link

Expected behavior

If the requested URL points to a folder with an index.html file and it is missing a slash at the end, the server should respond with a redirect with a slash added at the end.

Actual behavior

If the requested URL points to a folder with an index.html file and it is missing a slash at the end, the server does not redirect with the slash added, making the browser think that the folder name is a file name, which in turn makes relative URLs work differently depending on whether or not the slash is present.

How to reproduce

  • Download and unpack this tiny project: koa-static-folder-bug.zip
  • npm install and npm start
  • Open http://localhost:3000/folder. Observe that no redirect took place. The image of a black square is displayed, even though image.png is in the parent directory of folder/index.html.
  • Open http://localhost:3000/folder/. Observe that the image is (correctly) not displayed.
@wesleyboar-fka-iosulfur
Copy link

wesleyboar-fka-iosulfur commented Jul 13, 2019

I support either resolving this issue with the expected behavior or an evaluation of the expected behavior.

I spent more time than I want to admit on a wild goose change, because I did not notice the missing slash in my URLs. But, I propose an alternate expected behavior.


Expected behavior

If the requested URL points to a folder with an index.html file and it is missing a slash at the end, the server should respond with a 404, not the index.html file (because folder describes a file—a different file than index.html).


Either, help the user out completely (my interpretation of the suggestion of the original poster); or, do not halfway help the user, thus leading to unexpected behavior.

@75lb
Copy link

75lb commented Oct 4, 2019

Hi, do you plan to implement the expected behaviour? If not, I'll need to implement a workaround requiring me hitting the disk for every incoming request to test whether the requested resource is a directory or not. This is obviously sub-optimal since downstream, koa-send will again stat the filesystem for each request.

@jonathanong
Copy link
Member

i thought this was an option...

@3imed-jaberi
Copy link
Member

I think this solved by this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants