summaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
Diffstat (limited to 'system')
-rw-r--r--system/admin/cache.go2
-rw-r--r--system/admin/handlers.go73
-rw-r--r--system/admin/server.go14
3 files changed, 52 insertions, 37 deletions
diff --git a/system/admin/cache.go b/system/admin/cache.go
index 0de45af..2abdb26 100644
--- a/system/admin/cache.go
+++ b/system/admin/cache.go
@@ -9,7 +9,7 @@ import (
)
// CacheControl sets the default cache policy on static asset responses
-func CacheControl(next http.HandlerFunc) http.HandlerFunc {
+func CacheControl(next http.Handler) http.Handler {
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
etag := db.ConfigCache("etag")
policy := fmt.Sprintf("max-age=%d, public, must-revalidate, proxy-revalidate", 60*60*24*30)
diff --git a/system/admin/handlers.go b/system/admin/handlers.go
index 41e1095..a4eda03 100644
--- a/system/admin/handlers.go
+++ b/system/admin/handlers.go
@@ -5,10 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
- "log"
"net/http"
- "os"
- "path/filepath"
"strings"
"time"
@@ -592,34 +589,42 @@ func searchHandler(res http.ResponseWriter, req *http.Request) {
res.Write(adminView)
}
-func staticAssetHandler(res http.ResponseWriter, req *http.Request) {
- path := req.URL.Path
- pathParts := strings.Split(path, "/")[1:]
- pwd, err := os.Getwd()
- if err != nil {
- log.Fatal("Coudln't get current directory to set static asset source.")
- }
-
- filePathParts := make([]string, len(pathParts)+2, len(pathParts)+2)
- filePathParts = append(filePathParts, pwd)
- filePathParts = append(filePathParts, "system")
- filePathParts = append(filePathParts, pathParts...)
-
- http.ServeFile(res, req, filepath.Join(filePathParts...))
-}
-
-func staticUploadHandler(res http.ResponseWriter, req *http.Request) {
- path := req.URL.Path
- pathParts := strings.Split(path, "/")[2:]
-
- pwd, err := os.Getwd()
- if err != nil {
- log.Fatal("Coudln't get current directory to set static asset source.")
- }
-
- filePathParts := make([]string, len(pathParts)+1, len(pathParts)+1)
- filePathParts = append(filePathParts, pwd)
- filePathParts = append(filePathParts, pathParts...)
-
- http.ServeFile(res, req, filepath.Join(filePathParts...))
-}
+// func staticAssetHandler(res http.ResponseWriter, req *http.Request) {
+// path := req.URL.Path
+// pathParts := strings.Split(path, "/")[1:]
+// pwd, err := os.Getwd()
+// if err != nil {
+// log.Fatal("Coudln't get current directory to set static asset source.")
+// }
+
+// var filePathParts = []string{}
+// filePathParts = append(filePathParts, pwd)
+// filePathParts = append(filePathParts, "cmd")
+// filePathParts = append(filePathParts, "ponzu")
+// filePathParts = append(filePathParts, "vendor")
+// filePathParts = append(filePathParts, "github.com")
+// filePathParts = append(filePathParts, "bosssauce")
+// filePathParts = append(filePathParts, "ponzu")
+// filePathParts = append(filePathParts, "system")
+// filePathParts = append(filePathParts, pathParts...)
+
+// fmt.Println(filepath.Join(filePathParts...))
+
+// http.ServeFile(res, req, filepath.Join(filePathParts...))
+// }
+
+// func staticUploadHandler(res http.ResponseWriter, req *http.Request) {
+// path := req.URL.Path
+// pathParts := strings.Split(path, "/")[2:]
+
+// pwd, err := os.Getwd()
+// if err != nil {
+// log.Fatal("Coudln't get current directory to set static asset source.")
+// }
+
+// filePathParts := make([]string, len(pathParts)+1, len(pathParts)+1)
+// filePathParts = append(filePathParts, pwd)
+// filePathParts = append(filePathParts, pathParts...)
+
+// http.ServeFile(res, req, filepath.Join(filePathParts...))
+// }
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)))))
}