diff --git a/backend/go.sum b/backend/go.sum deleted file mode 100644 index a1fba2b..0000000 --- a/backend/go.sum +++ /dev/null @@ -1,25 +0,0 @@ -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= -github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= -github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/backend/main.go b/backend/main.go deleted file mode 100644 index 8cae5b3..0000000 --- a/backend/main.go +++ /dev/null @@ -1,92 +0,0 @@ -package main - -import ( - "log" - "net/http" - "os" - "time" - - "github.com/arnab-afk/monaco/handler" - "github.com/gorilla/websocket" -) - -func main() { - // Configure logging with timestamps and file locations - log.SetFlags(log.LstdFlags | log.Lshortfile) - log.SetOutput(os.Stdout) - - log.Println("Starting Monaco code execution backend...") - - h := handler.NewHandler() - - // Create a middleware for request logging - loggingMiddleware := func(next http.HandlerFunc) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - startTime := time.Now() - log.Printf("[HTTP] %s %s %s", r.Method, r.URL.Path, r.RemoteAddr) - next(w, r) - log.Printf("[HTTP] %s %s completed in %v", r.Method, r.URL.Path, time.Since(startTime)) - } - } - - // Create a middleware for CORS - allow all origins - corsMiddleware := func(next http.HandlerFunc) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // Set CORS headers to allow any origin - w.Header().Set("Access-Control-Allow-Origin", "*") - w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE") - w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With") - w.Header().Set("Access-Control-Max-Age", "3600") - - // Handle preflight OPTIONS requests - if r.Method == http.MethodOptions { - w.WriteHeader(http.StatusOK) - return - } - next(w, r) - } - } - - // 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))) - http.HandleFunc("/queue-stats", corsMiddleware(loggingMiddleware(h.QueueStatsHandler))) - - port := ":8080" - log.Printf("Server started at %s", port) - log.Fatal(http.ListenAndServe(port, nil)) -}