Skip to content

Commit

Permalink
Fix matching service and storage blob connection issues + compose.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinlim277 committed Oct 19, 2024
1 parent 90717b7 commit bb68806
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion backend/transport/question_http_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
10 changes: 7 additions & 3 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion matching-service-api/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PORT=
PORT=9200
RABBIT_URI=
CORS_ORIGIN=

1 change: 1 addition & 0 deletions matching-service/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ RABBIT_URI=

REDIS_URI=

BACKEND_MATCH_URI="[BACKEND_URI]/match"
9 changes: 8 additions & 1 deletion matching-service/transport/request_questions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"os"
"io"
"matching-service/models"
"net/http"
Expand All @@ -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())
Expand Down
7 changes: 6 additions & 1 deletion peerprep/components/questionpage/Matchmaking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion storage-blob-api/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PORT=
PORT=9300
REDIS_URI=

0 comments on commit bb68806

Please sign in to comment.