Skip to content

Commit

Permalink
add: embed admin static files
Browse files Browse the repository at this point in the history
  • Loading branch information
sunwei committed Nov 9, 2024
1 parent 1f054c4 commit 7188841
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
3 changes: 1 addition & 2 deletions internal/interfaces/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ func (s *Server) registerAdminHandler() {

s.mux.HandleFunc("/admin/init", s.handler.InitHandler)

staticDir := adminStaticDir()
s.mux.Handle("/admin/static/", s.cache.Control(
http.StripPrefix("/admin/static",
http.FileServer(restrict(http.Dir(staticDir))))))
http.FileServer(adminStaticDir()))))

uploadsDir := application.UploadDir()
s.mux.Handle("/api/uploads/", s.record.Collect(s.cors.Handle(s.cache.Control(
Expand Down
12 changes: 8 additions & 4 deletions internal/interfaces/api/path.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package api

import (
"embed"
"log"
"net/http"
"os"
"path/filepath"
)

func adminStaticDir() string {
//go:embed admin/static/*
var staticFiles embed.FS

func adminStaticDir() http.FileSystem {
staticDir := os.Getenv("HUGOVERSE_ADMIN_STATIC_DIR")
if staticDir == "" {
staticDir = filepath.Join(getWd(), "internal", "interfaces", "api", "admin", "static")
return http.FS(staticFiles)
}
return staticDir
return http.Dir(staticDir)
}

func getWd() string {
Expand Down
2 changes: 1 addition & 1 deletion internal/interfaces/cli/vercurr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package cli
var CurrentVersion = Version{
Major: 0,
Minor: 0,
PatchLevel: 6,
PatchLevel: 7,
Suffix: "",
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.0.6",
"version": "0.0.7",
"name": "Hugoverse",
"description": "Headless CMS for Hugo",
"author": "sunwei",
Expand Down

0 comments on commit 7188841

Please sign in to comment.