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

bugfix the (non)existence of a slash when staticFolder is set #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

coderofsalvation
Copy link

so, as @reddec already expected the staticDir crashed when no trailing space existed in an URL.
This fix handles all possible situations:

situation input output
without slash e87-ecf98-ecf998-ef98
with slash e87-ecf98-ecf998-ef98/
with slashes e87-ecf98-ecf998-ef98/foo/bar foo/bar

the first two scenarios will correctly fallback to serving index.html

@reddec
Copy link
Owner

reddec commented Dec 29, 2023

@coderofsalvation thanks for the idea, I used it as basis in d2e405c . Could you please confirm that it will solve your case?

@coderofsalvation
Copy link
Author

coderofsalvation commented Dec 29, 2023

yup that works!
Btw. I've replaced/force-pushed this branch with another fix: it resolves index.html in any directory now (see commit)
This seems to be the default behaviour on many static-file http servers.

Copy link
Owner

@reddec reddec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea! Left few comments

Comment on lines +197 to +201
dir, err := f.Readdir(1)
if len(dir) > 0 {
f.Close()
return local.writeStaticFile( path + "/index.html", out )
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like Readdir here is overkill 😺

Could you please use something like this

if _, err := os.Stat("/path/to/whatever"); errors.Is(err, os.ErrNotExist) {
  // path/to/whatever does not exist
}

Also, for path concatenation it's better to use filepath.Join - it will take care of few corner cases

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

Successfully merging this pull request may close these issues.

None yet

2 participants