Skip to content

Commit ace9c6a

Browse files
committed
fix(lib/httpapi): redirect based on chatBasePath
1 parent 227ef9b commit ace9c6a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/httpapi/server.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"log/slog"
88
"net/http"
9+
"path/filepath"
910
"sync"
1011
"time"
1112

@@ -33,6 +34,7 @@ type Server struct {
3334
agentio *termexec.Process
3435
agentType mf.AgentType
3536
emitter *EventEmitter
37+
chatBasePath string
3638
}
3739

3840
func (s *Server) GetOpenAPI() string {
@@ -95,10 +97,11 @@ func NewServer(ctx context.Context, agentType mf.AgentType, process *termexec.Pr
9597
agentio: process,
9698
agentType: agentType,
9799
emitter: emitter,
100+
chatBasePath: chatBasePath,
98101
}
99102

100103
// Register API routes
101-
s.registerRoutes(chatBasePath)
104+
s.registerRoutes()
102105

103106
return s
104107
}
@@ -116,7 +119,7 @@ func (s *Server) StartSnapshotLoop(ctx context.Context) {
116119
}
117120

118121
// registerRoutes sets up all API endpoints
119-
func (s *Server) registerRoutes(chatBasePath string) {
122+
func (s *Server) registerRoutes() {
120123
// GET /status endpoint
121124
huma.Get(s.api, "/status", s.getStatus, func(o *huma.Operation) {
122125
o.Description = "Returns the current status of the agent."
@@ -158,7 +161,7 @@ func (s *Server) registerRoutes(chatBasePath string) {
158161
s.router.Handle("/", http.HandlerFunc(s.redirectToChat))
159162

160163
// Serve static files for the chat interface under /chat
161-
s.registerStaticFileRoutes(chatBasePath)
164+
s.registerStaticFileRoutes()
162165
}
163166

164167
// getStatus handles GET /status
@@ -305,14 +308,14 @@ func (s *Server) Stop(ctx context.Context) error {
305308
}
306309

307310
// registerStaticFileRoutes sets up routes for serving static files
308-
func (s *Server) registerStaticFileRoutes(chatBasePath string) {
309-
chatHandler := FileServerWithIndexFallback(chatBasePath)
311+
func (s *Server) registerStaticFileRoutes() {
312+
chatHandler := FileServerWithIndexFallback(s.chatBasePath)
310313

311314
// Mount the file server at /chat
312315
s.router.Handle("/chat", http.StripPrefix("/chat", chatHandler))
313316
s.router.Handle("/chat/*", http.StripPrefix("/chat", chatHandler))
314317
}
315318

316319
func (s *Server) redirectToChat(w http.ResponseWriter, r *http.Request) {
317-
http.Redirect(w, r, "/chat/embed", http.StatusTemporaryRedirect)
320+
http.Redirect(w, r, filepath.Join(s.chatBasePath, "embed"), http.StatusTemporaryRedirect)
318321
}

0 commit comments

Comments
 (0)