diff options
author | Steve Manuel <nilslice@gmail.com> | 2020-01-01 17:14:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-01 17:14:32 -0700 |
commit | 9bc41b703131aa42ca64265ab6fdeadc37841e66 (patch) | |
tree | 138e6b7d6f8bd5c879eff61ce85df95506546003 /system/admin/server.go | |
parent | 45730ba5b4de56fed27f79f8c822bb59d41f7a38 (diff) | |
parent | 6ee81caea4649d3fc3bb6b5bde0628cb91c8e6f5 (diff) |
Merge pull request #333 from mangelajo/env-vars-for-dirs
Allow data directories outside pwd
Diffstat (limited to 'system/admin/server.go')
-rw-r--r-- | system/admin/server.go | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/system/admin/server.go b/system/admin/server.go index 9f28a0d..b912d4d 100644 --- a/system/admin/server.go +++ b/system/admin/server.go @@ -7,6 +7,8 @@ import ( "os" "path/filepath" + "github.com/ponzu-cms/ponzu/system/cfg" + "github.com/ponzu-cms/ponzu/system" "github.com/ponzu-cms/ponzu/system/admin/user" "github.com/ponzu-cms/ponzu/system/api" @@ -46,18 +48,14 @@ func Run() { http.HandleFunc("/admin/edit/upload", user.Auth(editUploadHandler)) http.HandleFunc("/admin/edit/upload/delete", user.Auth(deleteUploadHandler)) - pwd, err := os.Getwd() - if err != nil { - log.Fatalln("Couldn't find current directory for file server.") - } + staticDir := cfg.AdminStaticDir() - staticDir := filepath.Join(pwd, "cmd", "ponzu", "vendor", "github.com", "ponzu-cms", "ponzu", "system") - http.Handle("/admin/static/", db.CacheControl(http.FileServer(restrict(http.Dir(staticDir))))) + http.Handle("/admin/static/", db.CacheControl(http.StripPrefix("/admin/static", http.FileServer(restrict(http.Dir(staticDir)))))) // API path needs to be registered within server package so that it is handled // even if the API server is not running. Otherwise, images/files uploaded // through the editor will not load within the admin system. - uploadsDir := filepath.Join(pwd, "uploads") + uploadsDir := cfg.UploadDir() http.Handle("/api/uploads/", api.Record(api.CORS(db.CacheControl(http.StripPrefix("/api/uploads/", http.FileServer(restrict(http.Dir(uploadsDir)))))))) // Database & uploads backup via HTTP route registered with Basic Auth middleware. |