From 90a2ff959a958e8f7654f577e88e942378b0a7c2 Mon Sep 17 00:00:00 2001 From: Miguel Angel Ajo Date: Sun, 29 Dec 2019 18:36:08 +0100 Subject: Allow data directories outside pwd Running ponzu-cms inside a docker container, and maintaining data files in a volume (or several) was not possible with the previous directory schema without copying files or binaries to the volume. This commit adds several environment variables to allow the administrator to specify paths for directories while retaining backwards compatibility. - PONZU_DATA_DIR : is the directory where all the data and other directories will be stored, still the other directories can be controlled by the other env variables. - PONZU_TLS_DIR : is the directory to store devcerts and autocerts - PONZU_ADMINSTATIC_DIR : directory where the admin static files are served from. - PONZU_UPLOAD_DIR: upload files directory - PONZU_SEARCH_DIR: index directory for searches --- system/admin/server.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'system/admin/server.go') 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. -- cgit v1.2.3