From a07fbfd7b7613bba556abb9290e4649f775d976c Mon Sep 17 00:00:00 2001 From: Luca Crema Date: Wed, 10 Jul 2024 14:27:11 +0200 Subject: [PATCH] Added baseurl somewhere --- internal/assets/templates/document.html | 12 ++++++------ internal/glance/glance.go | 11 ++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/internal/assets/templates/document.html b/internal/assets/templates/document.html index d126d8b..4d784bd 100644 --- a/internal/assets/templates/document.html +++ b/internal/assets/templates/document.html @@ -11,12 +11,12 @@ - - - - - - + + + + + + {{ block "document-head-after" . }}{{ end }} diff --git a/internal/glance/glance.go b/internal/glance/glance.go index 653be75..8520012 100644 --- a/internal/glance/glance.go +++ b/internal/glance/glance.go @@ -41,6 +41,7 @@ type Server struct { Host string `yaml:"host"` Port uint16 `yaml:"port"` AssetsPath string `yaml:"assets-path"` + BaseUrl string `yaml:"base-url"` StartedAt time.Time `yaml:"-"` } @@ -194,10 +195,10 @@ func (a *Application) Serve() error { // TODO: add HTTPS support mux := http.NewServeMux() - mux.HandleFunc("GET /{$}", a.HandlePageRequest) - mux.HandleFunc("GET /{page}", a.HandlePageRequest) - mux.HandleFunc("GET /api/pages/{page}/content/{$}", a.HandlePageContentRequest) - mux.Handle("GET /static/{path...}", http.StripPrefix("/static/", FileServerWithCache(http.FS(assets.PublicFS), 2*time.Hour))) + mux.HandleFunc(fmt.Sprintf("GET %s/{$}", a.Config.Server.BaseUrl), a.HandlePageRequest) + mux.HandleFunc(fmt.Sprintf("GET %s/{page}", a.Config.Server.BaseUrl), a.HandlePageRequest) + mux.HandleFunc(fmt.Sprintf("GET %s/api/pages/{page}/content/{$}", a.Config.Server.BaseUrl), a.HandlePageContentRequest) + mux.Handle(fmt.Sprintf("GET %s/static/{path...}", a.Config.Server.BaseUrl), http.StripPrefix(fmt.Sprintf("%s/static/", a.Config.Server.BaseUrl), FileServerWithCache(http.FS(assets.PublicFS), 2*time.Hour))) if a.Config.Server.AssetsPath != "" { absAssetsPath, err := filepath.Abs(a.Config.Server.AssetsPath) @@ -208,7 +209,7 @@ func (a *Application) Serve() error { slog.Info("Serving assets", "path", absAssetsPath) assetsFS := FileServerWithCache(http.Dir(a.Config.Server.AssetsPath), 2*time.Hour) - mux.Handle("/assets/{path...}", http.StripPrefix("/assets/", assetsFS)) + mux.Handle(fmt.Sprintf("%s/assets/{path...}", a.Config.Server.BaseUrl), http.StripPrefix("/assets/", assetsFS)) } server := http.Server{