From bb68806cf97ff33d95ab7f790371287a0c2e0d17 Mon Sep 17 00:00:00 2001 From: alvinlim277 Date: Sat, 19 Oct 2024 13:30:05 +0800 Subject: [PATCH] Fix matching service and storage blob connection issues + compose.yaml --- backend/transport/question_http_requests.go | 2 +- compose.yaml | 10 +++++++--- matching-service-api/.env.example | 2 +- matching-service/.env.example | 1 + matching-service/transport/request_questions.go | 9 ++++++++- peerprep/components/questionpage/Matchmaking.tsx | 7 ++++++- storage-blob-api/.env.example | 2 +- 7 files changed, 25 insertions(+), 8 deletions(-) diff --git a/backend/transport/question_http_requests.go b/backend/transport/question_http_requests.go index b37e604a51..cc8c69f159 100644 --- a/backend/transport/question_http_requests.go +++ b/backend/transport/question_http_requests.go @@ -25,7 +25,7 @@ func SetAllEndpoints(router *gin.Engine, db *database.QuestionDB, logger *common // enable CORS for the frontend func SetCors(router *gin.Engine, origin string) { router.Use(cors.New(cors.Config{ - AllowOrigins: []string{origin, "http://localhost"}, + AllowOrigins: []string{"http://host.docker.internal", origin}, AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, AllowHeaders: []string{"Origin", "Content-Type", "Content-Length", "Authorization"}, ExposeHeaders: []string{"Content-Length"}, diff --git a/compose.yaml b/compose.yaml index 0bfba901a8..7c5f328cfc 100644 --- a/compose.yaml +++ b/compose.yaml @@ -63,11 +63,15 @@ services: - "9100:5672" - "9101:15672" healthcheck: - test: rabbitmq-diagnostics -q ping + test: + [ + "CMD-SHELL", + "rabbitmq-diagnostics -q ping && rabbitmq-diagnostics -q check_running && rabbitmq-diagnostics -q check_local_alarms", + ] interval: 30s timeout: 10s retries: 5 - start_period: 10s + start_period: 30s matching-service: build: matching-service @@ -80,7 +84,7 @@ services: - action: rebuild path: matching-service target: matching-service/app - # TODO for some reason healthcheck doesnt really work, still ahve to manually start them + # TODO for some reason healthcheck doesnt really work, still ahve to manually start MS and MS-api depends_on: rabbitmq: condition: service_healthy diff --git a/matching-service-api/.env.example b/matching-service-api/.env.example index f3546c507c..28af422e62 100644 --- a/matching-service-api/.env.example +++ b/matching-service-api/.env.example @@ -1,4 +1,4 @@ -PORT= +PORT=9200 RABBIT_URI= CORS_ORIGIN= diff --git a/matching-service/.env.example b/matching-service/.env.example index aec81ad520..3a9910a6fa 100644 --- a/matching-service/.env.example +++ b/matching-service/.env.example @@ -2,3 +2,4 @@ RABBIT_URI= REDIS_URI= +BACKEND_MATCH_URI="[BACKEND_URI]/match" \ No newline at end of file diff --git a/matching-service/transport/request_questions.go b/matching-service/transport/request_questions.go index 5566f74236..8237499968 100644 --- a/matching-service/transport/request_questions.go +++ b/matching-service/transport/request_questions.go @@ -6,6 +6,7 @@ import ( "bytes" "encoding/json" "fmt" + "os" "io" "matching-service/models" "net/http" @@ -23,7 +24,13 @@ func FindSuitableQuestionId(topicTags []string, difficulty string, target *model return fmt.Errorf("failed to convert outgoing req to JSON: %s", err.Error()) } - req, err := http.NewRequest("POST", "http://localhost:9090/match", bytes.NewBuffer(reqBody)) + URI := os.Getenv("BACKEND_MATCH_URI") + + if URI == "" { + URI = "http://localhost:9090/match" + } + + req, err := http.NewRequest("POST", URI, bytes.NewBuffer(reqBody)) if err != nil { return fmt.Errorf("failed to make request: %s", err.Error()) diff --git a/peerprep/components/questionpage/Matchmaking.tsx b/peerprep/components/questionpage/Matchmaking.tsx index 4bf25d59ca..3d82deca83 100644 --- a/peerprep/components/questionpage/Matchmaking.tsx +++ b/peerprep/components/questionpage/Matchmaking.tsx @@ -104,11 +104,16 @@ const Matchmaking = () => { // for now 404 means no match found so dont stop matching on error, let request timeout return; } + stopTimer(); setIsMatching(false); // TODO: iron out what is in a match response and sync up with collab service rooms const matchRes: MatchResponse = res as MatchResponse; console.log("Match found!"); - console.debug(matchRes); + // display in a popup for now + const message = `Room ID: ${matchRes.data.roomId} + User1: ${matchRes.data.user1} + User2: ${matchRes.data.user2}`; + window.alert(message); }; usePeriodicCallback(queryResource, QUERY_INTERVAL_MILLISECONDS, isMatching); diff --git a/storage-blob-api/.env.example b/storage-blob-api/.env.example index cab6778ac7..8b3519dc88 100644 --- a/storage-blob-api/.env.example +++ b/storage-blob-api/.env.example @@ -1,3 +1,3 @@ -PORT= +PORT=9300 REDIS_URI=