diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 62fe881..7ed1e6c 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -53,10 +53,11 @@ app.get('/flags/question', async (req, res) => { } }); -app.get('/flags/answer', async (req, res) => { +app.post('/flags/answer', async (req, res) => { try { + const answer = req.body.answer; // Forward the request to the question service - const questionResponse = await axios.get(questionServiceUrl+'/flags/answer', req.body); + const questionResponse = await axios.post(questionServiceUrl+'/flags/answer', answer, { headers: {'Content-Type': 'text/plain'} }); res.json(questionResponse.data); } catch (error) { res.status(error.response.status).json({ error: error.response.data.error }); diff --git a/questionservice/question-service.js b/questionservice/question-service.js index aec6f7d..5264d06 100644 --- a/questionservice/question-service.js +++ b/questionservice/question-service.js @@ -8,7 +8,6 @@ const app = express(); const port = 8010; app.use(express.static('public')); - app.use(express.text()); //Correct image @@ -107,18 +106,17 @@ app.get('/flags/question', async (req, res) => { * or not "false". In case it was incorrect, the chosen * country will be returned as well */ -app.get('/flags/answer', (req, res) => { - const answeredFlag = req.body - console.log(answeredFlag); - console.log(correctAnswerFlag); - if(correctAnswerFlag==answeredFlag){ +app.post('/flags/answer', (req, res) => { + const answer = req.body; + + if(correctAnswerFlag==answer){ res.json({ correct: "true" }) } else { res.json({ correct: "false", - country: `${flagToCountryMap.get(answeredFlag)}` + country: `${flagToCountryMap.get(answer)}` }) } }); diff --git a/webapp/src/components/Question.jsx b/webapp/src/components/Question.jsx index 35424d8..d9001d2 100644 --- a/webapp/src/components/Question.jsx +++ b/webapp/src/components/Question.jsx @@ -3,7 +3,7 @@ import axios from "axios"; const Question = () => { const apiEndpoint = 'http://localhost:8000'; - const [question, setQuestion] = useState([]) + const [question, setQuestion] = useState([]); const [loading, setLoading] = useState(true); const fetchQuestion = async () => { @@ -19,8 +19,7 @@ const Question = () => { const answerQuestion = async (answer) => { try { setLoading(true); - const result = await axios.get(`${apiEndpoint}/flags/answer`, {answer}); // to fix - + const result = await axios.post(`${apiEndpoint}/flags/answer`, {answer}); const res = await axios.get(`${apiEndpoint}/flags/question`); setQuestion(res.data); setLoading(false);