Skip to content

Commit 51cdb22

Browse files
committed
feat: Update web handler to serve index.html from embedded filesystem and adjust .gitignore for new paths
1 parent 388bfa2 commit 51cdb22

3 files changed

Lines changed: 14 additions & 25 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,6 @@ config.db.backup.*
114114
node_modules/
115115
certs/
116116
test-results/
117-
playwright-report/
117+
playwright-report/
118+
web/index.html
119+
web/assets/

web/index.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

web/web.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@ var frontendFS embed.FS
1616
// NewHandler creates a new HTTP handler for serving the embedded web UI
1717
func NewHandler(logger *zap.SugaredLogger) http.Handler {
1818
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
19-
// Clean the path
20-
p := r.URL.Path
21-
if p == "" || p == "/" {
22-
p = "frontend/dist/index.html"
23-
} else {
24-
// Add frontend/dist prefix to all paths
25-
p = "frontend/dist" + strings.TrimPrefix(p, "/")
19+
// The /ui prefix is already stripped by http.StripPrefix in server.go
20+
// So paths come in as: "/" for index, "/assets/file.js" for assets
21+
p := strings.TrimPrefix(r.URL.Path, "/")
22+
if p == "" {
23+
p = "index.html"
2624
}
2725

26+
// Build full path within embedded FS
27+
fullPath := "frontend/dist/" + p
28+
2829
// Try to read the file
29-
content, err := fs.ReadFile(frontendFS, p)
30+
content, err := fs.ReadFile(frontendFS, fullPath)
3031
if err != nil {
3132
// If file not found, serve index.html (for SPA routing)
3233
content, err = fs.ReadFile(frontendFS, "frontend/dist/index.html")
@@ -35,11 +36,11 @@ func NewHandler(logger *zap.SugaredLogger) http.Handler {
3536
http.Error(w, "Not found", http.StatusNotFound)
3637
return
3738
}
38-
p = "frontend/dist/index.html"
39+
fullPath = "frontend/dist/index.html"
3940
}
4041

4142
// Set content type based on file extension
42-
ext := path.Ext(p)
43+
ext := path.Ext(fullPath)
4344
contentType := "text/html"
4445
switch ext {
4546
case ".js":

0 commit comments

Comments
 (0)