// DirServer returns a fractals.Handler which servers a giving directory // every single time it receives a request. func DirServer(dir string) fractals.Handler { return fractals.SubLift(func(rw *Request, data []byte) (*Request, error) { if _, err := rw.Res.Write(data); err != nil { return nil, err } return rw, nil }, IdentityMiddlewareHandler(), fractals.Replay(dir), fs.ReadDirPath(), fs.SkipStat(fs.IsDir), fs.UnwrapStats(), JSONEncoder()) }
// FileServer returns a handler capable of serving different files from the provided // directory but using inputed URL path. func FileServer(dir string, prefix string) fractals.Handler { var stripper fractals.Handler if prefix != "" { stripper = fs.StripPrefix(prefix) } else { stripper = fractals.IdentityHandler() } return fractals.SubLift(func(rw *Request, data []byte) (*Request, error) { if _, err := rw.Res.Write(data); err != nil { return nil, err } return rw, nil }, IdentityMiddlewareHandler(), MimeWriter(), PathName(), stripper, fs.ResolvePathStringIn(dir), fs.ReadFile()) }