MCPcopy Create free account
hub / github.com/astercloud/aster / Start

Method Start

pkg/desktop/bridge_web.go:55–100  ·  view source on GitHub ↗

Start starts the HTTP server

(ctx context.Context)

Source from the content-addressed store, hash-verified

53
54// Start starts the HTTP server
55func (b *WebBridge) Start(ctx context.Context) error {
56 b.ctx, b.cancel = context.WithCancel(ctx)
57
58 mux := http.NewServeMux()
59
60 // API endpoints
61 mux.HandleFunc("/api/chat", b.handleChat)
62 mux.HandleFunc("/api/cancel", b.handleCancel)
63 mux.HandleFunc("/api/approve", b.handleApprove)
64 mux.HandleFunc("/api/status", b.handleStatus)
65 mux.HandleFunc("/api/history", b.handleHistory)
66 mux.HandleFunc("/api/config", b.handleConfig)
67 mux.HandleFunc("/api/agents", b.handleAgents)
68
69 // SSE endpoint for events
70 mux.HandleFunc("/api/events", b.handleSSE)
71
72 // Health check
73 mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
74 _ = json.NewEncoder(w).Encode(map[string]any{
75 "status": "ok",
76 "framework": "web",
77 "port": b.port,
78 "agents": len(b.agents),
79 })
80 })
81
82 // CORS middleware
83 handler := corsMiddleware(mux)
84
85 b.server = &http.Server{
86 Addr: fmt.Sprintf(":%d", b.port),
87 Handler: handler,
88 }
89
90 // Start server in goroutine
91 go func() {
92 ln, err := net.Listen("tcp", b.server.Addr)
93 if err != nil {
94 return
95 }
96 _ = b.server.Serve(ln) // Server error logged by http.Server
97 }()
98
99 return nil
100}
101
102// Stop stops the HTTP server
103func (b *WebBridge) Stop(ctx context.Context) error {

Callers

nothing calls this directly

Calls 2

ServeMethod · 0.80
corsMiddlewareFunction · 0.70

Tested by

no test coverage detected