diff options
author | Miguel Angel Ajo <majopela@redhat.com> | 2019-12-29 18:36:08 +0100 |
---|---|---|
committer | Miguel Angel Ajo <majopela@redhat.com> | 2019-12-29 23:42:46 +0100 |
commit | 90a2ff959a958e8f7654f577e88e942378b0a7c2 (patch) | |
tree | 934b6d72979f0edf26f3c661b6b059b6d1753e37 /system/admin/server.go | |
parent | 45730ba5b4de56fed27f79f8c822bb59d41f7a38 (diff) |
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
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. |