@@ -76,28 +76,27 @@ func main() {
7676 // In Docker, we will copy the built 'out' directory to 'public'
7777 staticDir := "./public"
7878 mux .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
79- path := staticDir + r .URL .Path
80-
81- // Check if exact file exists (e.g., /favicon.ico, /_next/static/...)
82- if info , err := os .Stat (path ); err == nil && ! info .IsDir () {
83- http .ServeFile (w , r , path )
84- return
79+ // Clean the path (remove trailing slashes except for root)
80+ urlPath := r .URL .Path
81+ if urlPath != "/" && urlPath [len (urlPath )- 1 ] == '/' {
82+ urlPath = urlPath [:len (urlPath )- 1 ]
8583 }
84+ path := staticDir + urlPath
8685
87- // For routes like /metrics, try serving metrics.html (Next.js static export)
88- if r .URL .Path != "/" {
86+ // For non-root paths, try serving the .html file first (Next.js static export)
87+ // This handles /metrics -> metrics.html
88+ if urlPath != "/" {
8989 htmlPath := path + ".html"
9090 if info , err := os .Stat (htmlPath ); err == nil && ! info .IsDir () {
9191 http .ServeFile (w , r , htmlPath )
9292 return
9393 }
94+ }
9495
95- // Also check for directory with index.html (e.g., /metrics/index.html)
96- indexPath := path + "/index.html"
97- if info , err := os .Stat (indexPath ); err == nil && ! info .IsDir () {
98- http .ServeFile (w , r , indexPath )
99- return
100- }
96+ // Check if exact file exists (e.g., /favicon.ico, /_next/static/...)
97+ if info , err := os .Stat (path ); err == nil && ! info .IsDir () {
98+ http .ServeFile (w , r , path )
99+ return
101100 }
102101
103102 // Default: serve index.html (home page or SPA fallback)
0 commit comments