A self-hosted dashboard that puts all your feeds in one place
Go aggregatordashboarddockerfeed-readergohomelabhomepagemonitoringredditrssrss-readerself-hostedstartpageyoutube
fix(serve): using paths without base url
CremaLuca23d6d411481e
diff --git a/internal/assets/static/main.js b/internal/assets/static/main.jsindex 9818ecf..5426c29 100644--- a/internal/assets/static/main.js+++ b/internal/assets/static/main.js@@ -21,10 +21,10 @@ function throttledDebounce(callback, maxDebounceTimes, debounceDelay) {};-async function fetchPageContent(pageSlug) {+async function fetchPageContent(pageData) {// TODO: handle non 200 status codes/time outs// TODO: add retries- const response = await fetch(`/api/pages/${pageSlug}/content/`);+ const response = await fetch(`${pageData.baseUrl}/api/pages/${pageData.slug}/content/`);const content = await response.text();return content;@@ -336,7 +336,7 @@ function setupCollapsibleGrids() {async function setupPage() {const pageElement = document.getElementById("page");const pageContentElement = document.getElementById("page-content");- const pageContent = await fetchPageContent(pageData.slug);+ const pageContent = await fetchPageContent(pageData);pageContentElement.innerHTML = pageContent;diff --git a/internal/assets/templates/page.html b/internal/assets/templates/page.htmlindex 98bb111..42e6bb2 100644--- a/internal/assets/templates/page.html+++ b/internal/assets/templates/page.html@@ -6,6 +6,7 @@<script>const pageData = {slug: "{{ .Page.Slug }}",+ baseUrl: "{{ .App.Config.Server.BaseUrl }}",};</script>{{ end }}@@ -14,13 +15,13 @@{{ define "document-head-after" }}{{ template "page-style-overrides.gotmpl" . }}{{ if ne "" .App.Config.Theme.CustomCSSFile }}-<link rel="stylesheet" href="{{ .App.Config.Theme.CustomCSSFile }}?v={{ .App.Config.Server.StartedAt.Unix }}">+<link rel="stylesheet" href="{{ .App.Config.Server.BaseUrl }}{{ .App.Config.Theme.CustomCSSFile }}?v={{ .App.Config.Server.StartedAt.Unix }}">{{ end }}{{ end }}{{ define "navigation-links" }}{{ range .App.Config.Pages }}-<a href="/{{ .Slug }}" class="nav-item{{ if eq .Slug $.Page.Slug }} nav-item-current{{ end }}">{{ .Title }}</a>+<a href="{{ $.App.Config.Server.BaseUrl }}/{{ .Slug }}" class="nav-item{{ if eq .Slug $.Page.Slug }} nav-item-current{{ end }}">{{ .Title }}</a>{{ end }}{{ end }}diff --git a/internal/glance/glance.go b/internal/glance/glance.goindex 8520012..dd9e40b 100644--- a/internal/glance/glance.go+++ b/internal/glance/glance.go@@ -41,7 +41,7 @@ type Server struct {Host string `yaml:"host"`Port uint16 `yaml:"port"`AssetsPath string `yaml:"assets-path"`- BaseUrl string `yaml:"base-url"`+ BaseUrl string `yaml:"base-url"`StartedAt time.Time `yaml:"-"`}@@ -195,10 +195,10 @@ func (a *Application) Serve() error {// TODO: add HTTPS supportmux := http.NewServeMux()- 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)))+ 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)))if a.Config.Server.AssetsPath != "" {absAssetsPath, err := filepath.Abs(a.Config.Server.AssetsPath)@@ -209,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(fmt.Sprintf("%s/assets/{path...}", a.Config.Server.BaseUrl), http.StripPrefix("/assets/", assetsFS))+ mux.Handle("/assets/{path...}", http.StripPrefix("/assets/", assetsFS))}server := http.Server{@@ -219,6 +219,6 @@ func (a *Application) Serve() error {a.Config.Server.StartedAt = time.Now()- slog.Info("Starting server", "host", a.Config.Server.Host, "port", a.Config.Server.Port)+ slog.Info("Starting server", "host", a.Config.Server.Host, "port", a.Config.Server.Port, "base url", a.Config.Server.BaseUrl)return server.ListenAndServe()}