Skip to content

net/http: mention StripPrefix in FileServer section #3530

Closed
@gopherbot

Description

@gopherbot

by sedaAK:

I wanted to put my /static subdirectory up as http://mysite/static, so I did the
following:

http.Handle("/static/",
http.FileServer(http.Dir("/projects/static")))

However browsing to http://mysite/static resolving to /projects/static/static, which
didn't exist.

So the code that ended up working is:
http.Handle("/static/", http.FileServer(http.Dir("/projects/")))

That looks totally wrong to me and causes a major limitation.  I want to say, mount this
directory there, not take this url path, then add it on to the filepath I give.   What
if I wanted the urlpath to not match the filepath?   If I want to call
http://mysite/somefiles and map it to /projects/someonesfolder  then I would be out of
luck and have to use some other muxer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions