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

file listing #7

Open
ncresswell opened this issue Nov 11, 2017 · 8 comments
Open

file listing #7

ncresswell opened this issue Nov 11, 2017 · 8 comments
Assignees

Comments

@ncresswell
Copy link

Hi there, is there any way to have this web server display a list of files in a directory rather than render the HTML? I would love to mount a persistent volume (that contains a bunch of files) to /srv/http and then be able to open the webpage of goStatic to download files from within that persistent volume

@PierreZ
Copy link
Owner

PierreZ commented Nov 12, 2017

Hi!

That's a cool idea, I"m starting to work on that.

@PierreZ PierreZ self-assigned this Nov 12, 2017
@PierreZ
Copy link
Owner

PierreZ commented Nov 13, 2017

File listing should be working without modifications according to the actual implementation 😄

@PierreZ
Copy link
Owner

PierreZ commented Nov 13, 2017

I just tried this:

./goStatic --path /home/pierre/workspace/personal/go/src/github.com/PierreZ/goStatic
2017/11/14 00:36:17 Listening at 0.0.0.0:8043...

# in another terminal
curl localhost:8043
<pre>
<a href=".git/">.git/</a>
<a href=".gitignore">.gitignore</a>
<a href=".travis.yml">.travis.yml</a>
<a href="Dockerfile">Dockerfile</a>
<a href="LICENSE">LICENSE</a>
<a href="README.md">README.md</a>
<a href="auth.go">auth.go</a>
<a href="goStatic">goStatic</a>
<a href="main.go">main.go</a>
</pre>

@shantanuthatte
Copy link

Now sorry to ask this. But is there a way to turn off directory listing?

I'm planning to use this as a static file server for js,fonts,css,etc. And I dont want people to browse the assets.

@dudeskeeroo
Copy link

This is probably a bit late for you, shantanuthatte, but here's a little workaround for others that have landed here through Google.

Create an index.html file in the directory that you want to disable listings in I've created an empty one and now file listings don't occur.

@utarwyn
Copy link

utarwyn commented Jul 18, 2021

Hello! Sorry to "re-open" that discussion but I'm facing a similar issue.

Maybe it's a good idea to add an option to answer with an HTTP error (403? 404? configurable?) when trying to access a directory with listing sets to off? Like Apache/Nginx do. Above solution is a working workaround but do not satisfy all use cases I think (because it prints a blank page and returns a valid HTTP code which does not really make sense).
image

Even if traditional webservers enable that feature by default, it may lead to a number of issues in a production environment. So, I propose to disable it by default and add an option called like "-enable-directory-listing". What do you think of that?

@PierreZ
Copy link
Owner

PierreZ commented Jul 19, 2021

I agree with you @utarwyn, would you like to open a PR? 🚀

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

No branches or pull requests

5 participants