diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-10-09 23:45:59 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-10-09 23:45:59 -0700 |
commit | 8ada2f203837d106932ba12fd2d7ca0af6e580e5 (patch) | |
tree | 04fad516b5b28a88bba420c5fa3eaf206f12eff5 /system/admin/server.go | |
parent | 72c812677caec723dc9e55679b9bca2f3d599b47 (diff) |
adding static file server, new implementation
Diffstat (limited to 'system/admin/server.go')
-rw-r--r-- | system/admin/server.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/system/admin/server.go b/system/admin/server.go index 312a3de..d5fd894 100644 --- a/system/admin/server.go +++ b/system/admin/server.go @@ -1,7 +1,10 @@ package admin import ( + "log" "net/http" + "os" + "path/filepath" "github.com/bosssauce/ponzu/system/admin/user" ) @@ -24,10 +27,17 @@ func Run() { http.HandleFunc("/admin/edit", user.Auth(editHandler)) http.HandleFunc("/admin/edit/upload", user.Auth(editUploadHandler)) - http.HandleFunc("/admin/static/", CacheControl(staticAssetHandler)) + pwd, err := os.Getwd() + if err != nil { + log.Fatal("Couldn't find current directory for file server.") + } + + staticDir := filepath.Join(pwd, "cmd", "ponzu", "vendor", "github.com", "bosssauce", "ponzu", "system") + http.Handle("/admin/static/", CacheControl(http.StripPrefix("/admin/", http.FileServer(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. - http.HandleFunc("/api/uploads/", CacheControl(staticUploadHandler)) + uploadsDir := filepath.Join(pwd, "uploads") + http.Handle("/api/uploads/", CacheControl(http.StripPrefix("/api/uploads/", http.FileServer(http.Dir(uploadsDir))))) } |