@@ -17,24 +17,46 @@ package server
1717import (
1818 "net/http"
1919 "os"
20+ "strings"
2021
22+ "github.com/bucketeer-io/bucketeer/ui/dashboard"
2123 webv2 "github.com/bucketeer-io/bucketeer/ui/web-v2"
2224)
2325
2426type spaFileSystem struct {
25- root http.FileSystem
27+ root http.FileSystem
28+ prefix string
2629}
2730
31+ // Open method for spaFileSystem
2832func (fs * spaFileSystem ) Open (name string ) (http.File , error ) {
33+ // First try with original path
2934 f , err := fs .root .Open (name )
30- if os .IsNotExist (err ) {
31- return fs . root . Open ( "index.html" )
35+ if ! os .IsNotExist (err ) {
36+ return f , err
3237 }
33- return f , err
38+
39+ // If file not found and we have a prefix, try stripping it
40+ if fs .prefix != "" && strings .HasPrefix (name , fs .prefix ) {
41+ strippedName := strings .TrimPrefix (name , fs .prefix )
42+ f , err = fs .root .Open (strippedName )
43+ if ! os .IsNotExist (err ) {
44+ return f , err
45+ }
46+ }
47+
48+ // If still not found, return index.html
49+ return fs .root .Open ("index.html" )
3450}
3551
52+ // webConsoleHandler returns a http.Handler for the old web console UI.
3653func webConsoleHandler () http.Handler {
37- return http .FileServer (& spaFileSystem {http .FS (webv2 .FS )})
54+ return http .FileServer (& spaFileSystem {root : http .FS (webv2 .FS )})
55+ }
56+
57+ // dashboardHandler returns a http.Handler for the new dashboard UI.
58+ func dashboardHandler () http.Handler {
59+ return http .FileServer (& spaFileSystem {root : http .FS (dashboard .FS ), prefix : "/v3/" })
3860}
3961
4062func webConsoleEnvJSHandler (path string ) http.Handler {
@@ -54,3 +76,14 @@ func (c WebConsoleService) Register(mux *http.ServeMux) {
5476 mux .HandleFunc ("/static/js/" ,
5577 http .StripPrefix ("/static/js/" , webConsoleEnvJSHandler (c .consoleEnvJSPath )).ServeHTTP )
5678}
79+
80+ type DashboardService struct {
81+ }
82+
83+ func NewDashboardService () DashboardService {
84+ return DashboardService {}
85+ }
86+
87+ func (d DashboardService ) Register (mux * http.ServeMux ) {
88+ mux .HandleFunc ("/" , dashboardHandler ().ServeHTTP )
89+ }
0 commit comments