Fix product performance grouped JSON build
This commit is contained in:
+21
@@ -227,6 +227,7 @@ InitRoutes — FULL V3 (Method-aware) PERMISSION EDITION
|
||||
func InitRoutes(pgDB *sql.DB, mssql *sql.DB, ml *mailer.GraphMailer) *mux.Router {
|
||||
|
||||
r := mux.NewRouter()
|
||||
mountUploads(r)
|
||||
mountSPA(r)
|
||||
|
||||
/*
|
||||
@@ -1517,6 +1518,26 @@ func main() {
|
||||
|
||||
}
|
||||
|
||||
func mountUploads(r *mux.Router) {
|
||||
root := strings.TrimSpace(os.Getenv("BLOB_ROOT"))
|
||||
if root == "" {
|
||||
return
|
||||
}
|
||||
uploadsRoot := filepath.Join(root, "uploads")
|
||||
if fi, err := os.Stat(uploadsRoot); err != nil || !fi.IsDir() {
|
||||
return
|
||||
}
|
||||
fileServer := http.StripPrefix("/uploads/", http.FileServer(http.Dir(uploadsRoot)))
|
||||
r.PathPrefix("/uploads/").Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet && r.Method != http.MethodHead {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Cache-Control", "public, max-age=3600")
|
||||
fileServer.ServeHTTP(w, r)
|
||||
})).Methods(http.MethodGet, http.MethodHead, http.MethodOptions)
|
||||
}
|
||||
|
||||
func mountSPA(r *mux.Router) {
|
||||
r.NotFoundHandler = http.HandlerFunc(spaIndex)
|
||||
r.HandleFunc("/", spaIndex).Methods(http.MethodGet)
|
||||
|
||||
Reference in New Issue
Block a user