@@ -76,8 +76,10 @@ func NewServer(port int, client client.Client) *Server {
7676 startTime : time .Now (),
7777 upgrader : websocket.Upgrader {
7878 CheckOrigin : func (r * http.Request ) bool {
79- return true // Allow all origins for now
79+ return true
8080 },
81+ ReadBufferSize : 1024 ,
82+ WriteBufferSize : 1024 ,
8183 },
8284 }
8385}
@@ -581,9 +583,7 @@ func (s *Server) handleHooks(w http.ResponseWriter, r *http.Request) {
581583 }
582584
583585 if r .Method == http .MethodPost {
584- // Create hook - for now, just return success
585- w .Header ().Set ("Content-Type" , "application/json" )
586- json .NewEncoder (w ).Encode (map [string ]string {"status" : "success" })
586+ s .handleCreateHook (w , r )
587587 return
588588 }
589589
@@ -697,6 +697,24 @@ func (s *Server) handleDeleteHook(w http.ResponseWriter, r *http.Request, namesp
697697 w .WriteHeader (http .StatusNoContent )
698698}
699699
700+ // handleCreateHook creates a new Hook resource
701+ func (s * Server ) handleCreateHook (w http.ResponseWriter , r * http.Request ) {
702+ var hook v1alpha2.Hook
703+ if err := json .NewDecoder (r .Body ).Decode (& hook ); err != nil {
704+ http .Error (w , "Invalid JSON" , http .StatusBadRequest )
705+ return
706+ }
707+
708+ if err := s .client .Create (context .Background (), & hook ); err != nil {
709+ s .logger .Error (err , "Failed to create hook" )
710+ http .Error (w , "Failed to create hook" , http .StatusInternalServerError )
711+ return
712+ }
713+
714+ w .Header ().Set ("Content-Type" , "application/json" )
715+ json .NewEncoder (w ).Encode (hook )
716+ }
717+
700718// handleHookValidation handles POST /api/v1/hooks/validate
701719func (s * Server ) handleHookValidation (w http.ResponseWriter , r * http.Request ) {
702720 if r .Method != http .MethodPost {
@@ -1133,17 +1151,7 @@ func (s *Server) handleMetrics(w http.ResponseWriter, r *http.Request) {
11331151
11341152// checkKagentConnectivity checks if the Kagent API is reachable
11351153func (s * Server ) checkKagentConnectivity () string {
1136- // This is a simplified connectivity check
1137- // In a real implementation, you might want to make an actual HTTP request
1138- // to the Kagent API endpoint to verify connectivity
1139-
1140- // For now, we'll return "unknown" since we don't have direct access
1141- // to the Kagent client configuration in this context
1142- // A more sophisticated implementation would:
1143- // 1. Get the Kagent API URL from environment variables or config
1144- // 2. Make a health check request to the API
1145- // 3. Return "connected", "disconnected", or "unknown" based on the response
1146-
1154+ // TODO: Implement actual Kagent API connectivity check
11471155 return "unknown"
11481156}
11491157
0 commit comments