From ec9dcd3e10e3fa58703b519d4d862ff000f36072 Mon Sep 17 00:00:00 2001 From: slashexx Date: Sun, 10 Nov 2024 19:23:07 +0000 Subject: [PATCH 1/2] Updated rust execution once more --- backend/code-execution-service/main.go | 37 +++++++++++++++----------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/backend/code-execution-service/main.go b/backend/code-execution-service/main.go index 8c77fab..4404ab3 100644 --- a/backend/code-execution-service/main.go +++ b/backend/code-execution-service/main.go @@ -41,7 +41,7 @@ func executeCode(language string, code string) (string, error) { switch language { case "go": - fmt.Println("Go file name is :"+tmpFile.Name()) + fmt.Println("Go file name is :" + tmpFile.Name()) cmd = exec.Command("go", "run", tmpFile.Name()) case "python": cmd = exec.Command("python3", tmpFile.Name()) @@ -62,41 +62,47 @@ func executeCode(language string, code string) (string, error) { case "rs": execCmd := exec.Command("rustc", tmpFile.Name()) if err := execCmd.Run(); err != nil { - cmdOutput,_ := execCmd.CombinedOutput() - + cmdOutput, _ := execCmd.CombinedOutput() + return string(cmdOutput), err + } + + binaryName := tmpFile.Name()[:len(tmpFile.Name())-len(".rs")] + cmd = exec.Command(binaryName) + cmdOutput, err := cmd.CombinedOutput() + if err != nil { return string(cmdOutput), err } + return string(cmdOutput), nil + case "java": tmpFileName := filepath.Join(os.TempDir(), "Main.java") tmpFile, err = os.Create(tmpFileName) if err != nil { return "", err } - defer os.Remove(tmpFileName) - - + defer os.Remove(tmpFileName) + if _, err := tmpFile.Write([]byte(code)); err != nil { return "", err } - tmpFile.Close() - - + tmpFile.Close() + fmt.Printf("Compiling with command: %s %s\n", "javac", tmpFileName) execCmd := exec.Command("javac", tmpFileName) cmdOutput, err := execCmd.CombinedOutput() if err != nil { return string(cmdOutput), err } - + className := "Main" cmd = exec.Command("java", className) - cmd.Dir = filepath.Dir(tmpFileName) + cmd.Dir = filepath.Dir(tmpFileName) cmdOutput, err = cmd.CombinedOutput() if err != nil { return string(cmdOutput), err } return string(cmdOutput), nil - + default: return "", fmt.Errorf("unsupported language: %s", language) } @@ -106,12 +112,11 @@ func executeCode(language string, code string) (string, error) { } func enableCors(w http.ResponseWriter) { - w.Header().Set("Access-Control-Allow-Origin", "https://codebrewery.vercel.app") - w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS") - w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + w.Header().Set("Access-Control-Allow-Origin", "https://codebrewery.vercel.app") + w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS") + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") } - func executeHandler(w http.ResponseWriter, r *http.Request) { fmt.Printf("Received %s request for %s\n", r.Method, r.URL.Path) enableCors(w) From f9da78fe715d16e72383b0cc641589581215ae88 Mon Sep 17 00:00:00 2001 From: slashexx Date: Sun, 10 Nov 2024 19:24:04 +0000 Subject: [PATCH 2/2] Updated rust execution once more --- frontend/.dockerignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 frontend/.dockerignore diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..4842568 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,3 @@ +node_modules +*.log +*.git