@@ -37,14 +37,19 @@ func NewHTTPHandlers(client *Client) *HTTPHandlers {
3737 }
3838}
3939
40- func (h * HTTPHandlers ) RegisterHandlers (mux * http.ServeMux , embeddedFS * embed.FS ) {
40+ func (h * HTTPHandlers ) RegisterHandlers (mux * http.ServeMux , assetsFS * embed. FS , staticFS * embed.FS ) {
4141 mux .HandleFunc ("/api/render" , h .handleRender )
4242 mux .HandleFunc ("/api/updates" , h .handleSSE )
4343 mux .HandleFunc ("/files/" , h .handleAssetsUrl )
44-
44+
45+ // Add handler for static files at /static/ path
46+ if staticFS != nil {
47+ mux .HandleFunc ("/static/" , h .handleStaticPathFiles (staticFS ))
48+ }
49+
4550 // Add fallback handler for embedded static files in production mode
46- if embeddedFS != nil {
47- mux .HandleFunc ("/" , h .handleStaticFiles (embeddedFS ))
51+ if assetsFS != nil {
52+ mux .HandleFunc ("/" , h .handleStaticFiles (assetsFS ))
4853 }
4954}
5055
@@ -238,7 +243,7 @@ func (h *HTTPHandlers) handleSSE(w http.ResponseWriter, r *http.Request) {
238243func (h * HTTPHandlers ) handleStaticFiles (embeddedFS * embed.FS ) http.HandlerFunc {
239244 // Create a file server from the embedded FS
240245 fileServer := http .FileServer (http .FS (embeddedFS ))
241-
246+
242247 return func (w http.ResponseWriter , r * http.Request ) {
243248 defer func () {
244249 panicErr := util .PanicHandler ("handleStaticFiles" , recover ())
@@ -262,3 +267,26 @@ func (h *HTTPHandlers) handleStaticFiles(embeddedFS *embed.FS) http.HandlerFunc
262267 fileServer .ServeHTTP (w , r )
263268 }
264269}
270+
271+ func (h * HTTPHandlers ) handleStaticPathFiles (staticFS * embed.FS ) http.HandlerFunc {
272+ // Create a file server from the embedded FS
273+ fileServer := http .FileServer (http .FS (staticFS ))
274+
275+ return func (w http.ResponseWriter , r * http.Request ) {
276+ defer func () {
277+ panicErr := util .PanicHandler ("handleStaticPathFiles" , recover ())
278+ if panicErr != nil {
279+ http .Error (w , fmt .Sprintf ("internal server error: %v" , panicErr ), http .StatusInternalServerError )
280+ }
281+ }()
282+
283+ // Strip /static/ prefix from the path
284+ r .URL .Path = strings .TrimPrefix (r .URL .Path , "/static" )
285+ if r .URL .Path == "" {
286+ r .URL .Path = "/"
287+ }
288+
289+ // Serve the file using Go's file server
290+ fileServer .ServeHTTP (w , r )
291+ }
292+ }
0 commit comments