fix some bugs and add stuff to config

pull/144/head
Henrique Dias 2016-08-21 20:25:40 +01:00
parent 8d0214f74a
commit 408fa2e86f
3 changed files with 7 additions and 8 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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)