From fec04fa9f044b0103e31b800ce81412dd7301d27 Mon Sep 17 00:00:00 2001 From: AndrewSC208 Date: Sat, 19 Apr 2025 13:27:02 -0500 Subject: [PATCH] Making the asset host directory configurable by the service --- pkg/chassis/builder.go | 4 ++-- pkg/chassis/client_application.go | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/pkg/chassis/builder.go b/pkg/chassis/builder.go index 69db4f2..85357df 100644 --- a/pkg/chassis/builder.go +++ b/pkg/chassis/builder.go @@ -81,8 +81,8 @@ func (c *Runtime) WithSecretStore(plugin SecretStore) *Runtime { return c } -func (c *Runtime) WithClientApplication(files embed.FS) *Runtime { - c.withClientApplication(files) +func (c *Runtime) WithClientApplication(files embed.FS, rootDir string) *Runtime { + c.withClientApplication(files, rootDir) return c } diff --git a/pkg/chassis/client_application.go b/pkg/chassis/client_application.go index ed3d9ba..9108f74 100644 --- a/pkg/chassis/client_application.go +++ b/pkg/chassis/client_application.go @@ -9,10 +9,6 @@ import ( "strings" ) -const ( - webClientRoot = "web-client/dist" -) - // NOTE: the logic for serving a SPA is modified from the example here: https://github.com/gorilla/mux#serving-single-page-applications // spaHandler implements the http.Handler interface, so we can use it @@ -65,7 +61,7 @@ func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.ServeFileFS(w, r, h.fileSystem, path) } -func (c *Runtime) withClientApplication(e embed.FS) { +func (c *Runtime) withClientApplication(e embed.FS, rootDir string) { // Init and store the http multiplexer if c.mux == nil { c.mux = http.NewServeMux() @@ -73,13 +69,13 @@ func (c *Runtime) withClientApplication(e embed.FS) { spa := spaHandler{ indexPath: "index.html", - fileSystem: c.getFileSystem(e), + fileSystem: c.getFileSystem(e, rootDir), } c.mux.Handle("/", spa) } -func (c *Runtime) getFileSystem(e embed.FS) fs.FS { - fsys, err := fs.Sub(e, webClientRoot) +func (c *Runtime) getFileSystem(e embed.FS, rootDir string) fs.FS { + fsys, err := fs.Sub(e, rootDir) if err != nil { panic(err) }