Implement WebSocket support for terminal connections and enhance terminal UI
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/arnab-afk/monaco/handler"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -46,7 +47,40 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Register handlers with logging and CORS middleware
|
||||
// Configure WebSocket upgrader
|
||||
upgrader := websocket.Upgrader{
|
||||
ReadBufferSize: 1024,
|
||||
WriteBufferSize: 1024,
|
||||
// Allow connections from any origin
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
}
|
||||
|
||||
// WebSocket handler for terminal connection
|
||||
http.HandleFunc("/ws/terminal", func(w http.ResponseWriter, r *http.Request) {
|
||||
// Get execution ID from query parameters
|
||||
executionID := r.URL.Query().Get("id")
|
||||
if executionID == "" {
|
||||
log.Println("[WS] Missing execution ID")
|
||||
http.Error(w, "Missing execution ID", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Upgrade HTTP connection to WebSocket
|
||||
conn, err := upgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
log.Printf("[WS] Failed to upgrade connection: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("[WS] Terminal connection established for execution ID: %s", executionID)
|
||||
|
||||
// Connect this WebSocket to the execution service for real-time streaming
|
||||
h.ConnectTerminal(conn, executionID)
|
||||
})
|
||||
|
||||
// Register REST API handlers with logging and CORS middleware
|
||||
http.HandleFunc("/submit", corsMiddleware(loggingMiddleware(h.SubmitHandler)))
|
||||
http.HandleFunc("/status", corsMiddleware(loggingMiddleware(h.StatusHandler)))
|
||||
http.HandleFunc("/result", corsMiddleware(loggingMiddleware(h.ResultHandler)))
|
||||
|
||||
Reference in New Issue
Block a user