|
6 | 6 | "fmt"
|
7 | 7 | "log"
|
8 | 8 | "net/http"
|
| 9 | + "io/ioutil" |
9 | 10 | )
|
10 | 11 |
|
11 | 12 | type CodeRequest struct {
|
@@ -35,24 +36,32 @@ func executeCode(w http.ResponseWriter, r *http.Request) {
|
35 | 36 | return
|
36 | 37 | }
|
37 | 38 |
|
| 39 | + log.Printf("Request body: %+v", req) |
38 | 40 |
|
39 | 41 | reqBody, err := json.Marshal(req)
|
40 | 42 | if err != nil {
|
41 | 43 | log.Printf("Error marshaling request: %v", err)
|
42 | 44 | http.Error(w, "Failed to marshal request", http.StatusInternalServerError)
|
43 | 45 | return
|
44 | 46 | }
|
45 |
| -// https://codebrewery-code-execution-service.onrender.com |
46 |
| - resp, err := http.Post("https://codebrewery-code-execution-service.onrender.com", "application/json", bytes.NewBuffer(reqBody)) |
| 47 | + |
| 48 | + url := "https://codebrewery-code-execution-service.onrender.com" |
| 49 | + log.Printf("Sending request to Code Execution Service: %s", url) |
| 50 | + |
| 51 | + resp, err := http.Post(url, "application/json", bytes.NewBuffer(reqBody)) |
47 | 52 | if err != nil {
|
48 | 53 | log.Printf("Error contacting code execution service: %v", err)
|
49 | 54 | http.Error(w, "Failed to execute code", http.StatusInternalServerError)
|
50 | 55 | return
|
51 | 56 | }
|
52 | 57 | defer resp.Body.Close()
|
53 | 58 |
|
| 59 | + log.Printf("Received response status: %d", resp.StatusCode) |
| 60 | + |
54 | 61 | if resp.StatusCode != http.StatusOK {
|
55 | 62 | log.Printf("Code execution service returned status: %d", resp.StatusCode)
|
| 63 | + responseBody, _ := ioutil.ReadAll(resp.Body) |
| 64 | + log.Printf("Response body: %s", string(responseBody)) |
56 | 65 | http.Error(w, "Code execution service returned an error", http.StatusInternalServerError)
|
57 | 66 | return
|
58 | 67 | }
|
|
0 commit comments