Chi: [Feature Request]Static File serving

Created on 31 Mar 2016  路  6Comments  路  Source: go-chi/chi

When I'm using chi for a project with swagger-ui, I feel it is not so convenient for serving static files. What about adding the static file serving feature like this:

func (mx *Mux) Static(path, root string) {
    fs := http.StripPrefix(path, http.FileServer(http.Dir(root)))
    mx.Get(path+"/*", func(w http.ResponseWriter, r *http.Request) {
        fs.ServeHTTP(w, r)
    })
}

Most helpful comment

Merged in #36 - see new mux.FileServer(path string, root http.FileSystem) method.. example usage: https://github.com/pressly/chi/blob/master/mux_test.go#L734-L743

All 6 comments

@netsharec I see what you mean. I'll add this function later today.

Please allow it to take an http.FileSystem instead of directory so we can serve static files from memory. I often do that along with go-bindata.

@fiorix good call

Merged in #36 - see new mux.FileServer(path string, root http.FileSystem) method.. example usage: https://github.com/pressly/chi/blob/master/mux_test.go#L734-L743

@pkieltyka: Is it correct that this functionality doesn't exist anymore, but instead you have to follow this example?

yep, thats correct

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nhooyr picture nhooyr  路  12Comments

gpopovic picture gpopovic  路  5Comments

MrXu picture MrXu  路  3Comments

mvrlin picture mvrlin  路  6Comments

rocanion picture rocanion  路  4Comments