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

Can't serve files from outside / #5

Closed
gavbaa opened this issue Apr 6, 2014 · 3 comments
Closed

Can't serve files from outside / #5

gavbaa opened this issue Apr 6, 2014 · 3 comments

Comments

@gavbaa
Copy link

gavbaa commented Apr 6, 2014

Using example.go from this repo as is works just fine. If I change:

    http.Handle("/", http.FileServer(box.HTTPBox()))

to

    http.Handle("/files", http.FileServer(box.HTTPBox()))

(or "/files/" with a trailing slash), everything 404s at any reasonable URL to test, the directory indexes don't work and so forth. I tried /file.txt, /files, /files/, /files/file.txt and several other variations. Am I instantiating something wrong, or is there a path issue here?

@GeertJohan
Copy link
Owner

You probably want to use http.StipPrefix() (http://golang.org/pkg/net/http/#StripPrefix)
e.g.: http.Handle("/files/", http.StripPrefix("/files/", http.FileServer(box.HTTPBox())))

Does this solve your problem?

@gavbaa
Copy link
Author

gavbaa commented Apr 6, 2014

Shoot, yes. Thanks for the pointer, sorry about that!

I'd love to see an example of that in the docs, I'll bet it's a common use case to want to serve a subdirectory of static assets in a site.

@gavbaa gavbaa closed this as completed Apr 6, 2014
@GeertJohan
Copy link
Owner

Np. Glad you got it working :)

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

2 participants