diff --git a/config/config.go b/config/config.go index f116952c..e41b59ec 100644 --- a/config/config.go +++ b/config/config.go @@ -70,7 +70,8 @@ func Parse(c *caddy.Controller) ([]Config, error) { for c.Next() { var cfg = Config{UserConfig: &UserConfig{}} - cfg.PathScope = "./" + cfg.PathScope = "." + cfg.Root = http.Dir(cfg.PathScope) cfg.BaseURL = "" cfg.FrontMatter = "yaml" cfg.HugoEnabled = false @@ -235,8 +236,6 @@ func Parse(c *caddy.Controller) ([]Config, error) { cfg.BaseURL = strings.TrimSuffix(cfg.BaseURL, "/") cfg.BaseURL = "/" + cfg.BaseURL - cfg.Root = http.Dir(cfg.PathScope) - caddyConf := httpserver.GetConfig(c) cfg.AbsoluteURL = strings.TrimSuffix(caddyConf.Addr.Path, "/") + "/" + cfg.BaseURL cfg.AbsoluteURL = strings.Replace(cfg.AbsoluteURL, "//", "/", -1) diff --git a/directory/file.go b/directory/file.go index 7e371c7b..106e75d3 100644 --- a/directory/file.go +++ b/directory/file.go @@ -37,14 +37,14 @@ type Info struct { // GetInfo gets the file information and, in case of error, returns the // respective HTTP error code -func GetInfo(url *url.URL, c *config.Config) (*Info, int, error) { +func GetInfo(url *url.URL, c *config.Config, u *config.UserConfig) (*Info, int, error) { var err error rootPath := strings.Replace(url.Path, c.BaseURL, "", 1) rootPath = strings.TrimPrefix(rootPath, "/") rootPath = "/" + rootPath - relpath := c.PathScope + rootPath + relpath := u.PathScope + rootPath relpath = strings.Replace(relpath, "\\", "/", -1) relpath = filepath.Clean(relpath) @@ -53,7 +53,7 @@ func GetInfo(url *url.URL, c *config.Config) (*Info, int, error) { RootPath: rootPath, Path: relpath, } - f, err := c.Root.Open(rootPath) + f, err := u.Root.Open(rootPath) if err != nil { return file, errors.ToHTTPCode(err), err } @@ -188,7 +188,7 @@ func (i *Info) serveSingleFile(w http.ResponseWriter, r *http.Request, c *config func (i *Info) serveListing(w http.ResponseWriter, r *http.Request, c *config.Config, u *config.UserConfig) (int, error) { var err error - file, err := c.Root.Open(i.RootPath) + file, err := u.Root.Open(i.RootPath) if err != nil { return errors.ToHTTPCode(err), err } diff --git a/filemanager.go b/filemanager.go index e24f5842..6ad0f809 100644 --- a/filemanager.go +++ b/filemanager.go @@ -57,7 +57,7 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err } if r.Method != http.MethodPost && !serveAssets { - fi, code, err = directory.GetInfo(r.URL, c) + fi, code, err = directory.GetInfo(r.URL, c, user) if err != nil { if r.Method == http.MethodGet { return errors.PrintHTML(w, code, err)