goStatic icon indicating copy to clipboard operation
goStatic copied to clipboard

file listing

Open ncresswell opened this issue 8 years ago • 8 comments

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

ncresswell avatar Nov 11 '17 21:11 ncresswell

Hi!

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

PierreZ avatar Nov 12 '17 15:11 PierreZ

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

PierreZ avatar Nov 13 '17 23:11 PierreZ

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>

PierreZ avatar Nov 13 '17 23:11 PierreZ

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.

shantanuthatte avatar Jul 11 '18 15:07 shantanuthatte

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.

dudeskeeroo avatar Aug 09 '19 00:08 dudeskeeroo

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?

utarwyn avatar Jul 18 '21 23:07 utarwyn

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

PierreZ avatar Jul 19 '21 06:07 PierreZ