Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Template helper uses hardcoded path ignoring configurable URL
- Updated the template
statichelper to build URLs from the configuredStatic.URL(with/staticfallback) and wired that value through renderer initialization with tests for custom and CDN URLs.
- Updated the template
Or push these changes by commenting:
@cursor push 33bfa46b60
Preview (33bfa46b60)
diff --git a/pkg/server/routes.go b/pkg/server/routes.go
--- a/pkg/server/routes.go
+++ b/pkg/server/routes.go
@@ -14,7 +14,7 @@
func (s *Server) setupRoutes() (err error) {
// Setup HTML template renderer.
- if s.router.HTMLRender, err = web.NewRender(web.Templates()); err != nil {
+ if s.router.HTMLRender, err = web.NewRender(web.Templates(), s.conf.Static.URL); err != nil {
return err
}
diff --git a/pkg/web/web.go b/pkg/web/web.go
--- a/pkg/web/web.go
+++ b/pkg/web/web.go
@@ -7,6 +7,7 @@
"html/template"
"io/fs"
"log/slog"
+ "net/url"
"path/filepath"
"strings"
"time"
@@ -43,9 +44,10 @@
}
// Creates a new template renderer from the default templates.
-func NewRender(fsys fs.FS) (render *Render, err error) {
+func NewRender(fsys fs.FS, staticURL string) (render *Render, err error) {
render = &Render{
templates: make(map[string]*template.Template),
+ staticURL: staticURL,
}
// Add the pages patterns
@@ -77,6 +79,7 @@
type Render struct {
templates map[string]*template.Template
funcs template.FuncMap
+ staticURL string
}
var _ render.HTMLRender = (*Render)(nil)
@@ -119,7 +122,7 @@
func (r *Render) FuncMap() template.FuncMap {
if r.funcs == nil {
r.funcs = template.FuncMap{
- "static": static,
+ "static": r.static,
"titlecase": titlecase,
"lowercase": lowercase,
"uppercase": uppercase,
@@ -150,10 +153,21 @@
return t.Format("January 2, 2006 3:04 PM")
}
-func static(path string) string {
- return filepath.Join("/static", path)
+func (r *Render) static(path string) string {
+ return staticURL(r.staticURL, path)
}
+func staticURL(base, path string) string {
+ if base == "" {
+ base = "/static"
+ }
+
+ if joined, err := url.JoinPath(base, path); err == nil {
+ return joined
+ }
+ return strings.TrimSuffix(base, "/") + "/" + strings.TrimPrefix(path, "/")
+}
+
func currentYear() int {
return time.Now().Year()
}
diff --git a/pkg/web/web_test.go b/pkg/web/web_test.go
--- a/pkg/web/web_test.go
+++ b/pkg/web/web_test.go
@@ -9,7 +9,7 @@
)
func TestRender(t *testing.T) {
- renderer, err := web.NewRender(web.Templates())
+ renderer, err := web.NewRender(web.Templates(), "/static")
require.NoError(t, err)
require.NotNil(t, renderer)
}
@@ -104,4 +104,23 @@
require.Equal(t, testCase.expected, f(testCase.input))
}
})
+
+ t.Run("static configurable base url", func(t *testing.T) {
+ renderer, err := web.NewRender(web.Templates(), "/assets")
+ require.NoError(t, err)
+ funcMap := renderer.FuncMap()
+
+ f := funcMap["static"].(func(string) string)
+ require.Equal(t, "/assets/favicon.ico", f("/favicon.ico"))
+ require.Equal(t, "/assets/css/style.css", f("css/style.css"))
+ })
+
+ t.Run("static configurable remote url", func(t *testing.T) {
+ renderer, err := web.NewRender(web.Templates(), "https://cdn.example.com/uptime")
+ require.NoError(t, err)
+ funcMap := renderer.FuncMap()
+
+ f := funcMap["static"].(func(string) string)
+ require.Equal(t, "https://cdn.example.com/uptime/img/logo.png", f("img/logo.png"))
+ })
}This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Scope of changes
Serves static assets from the filesystem rather than building them into the binary.
Estimated PR Size:
Acceptance criteria
This PR will be merged without review.
Author checklist
Note
Medium Risk
Changes how static assets are packaged and served (Docker image + runtime routing/config), so misconfiguration or missing files could break UI assets in production. Validation and tests reduce risk, but it affects runtime behavior and deployment defaults.
Overview
Updates the service to serve static assets from the container filesystem instead of embedding them in the Go binary.
The Docker image now copies
pkg/web/staticinto/var/www/html, exposes port8000, and sets new env defaults (UPTIME_STATIC_SERVE,UPTIME_STATIC_ROOT,UPTIME_STATIC_URL). Runtime routing switches/static(plus/favicon.icoand/robots.txt) to be served viaos.DirFSwhen enabled, and configuration adds/validates a newStaticsection (including URL vs filesystem constraints) with accompanying unit tests.Written by Cursor Bugbot for commit af34fe9. Configure here.