From 5ae236a71359fb9e8b832d2ab72e40cef999e619 Mon Sep 17 00:00:00 2001 From: sergiollende Date: Thu, 21 Mar 2024 18:00:14 +0100 Subject: [PATCH] Try to connect with WikiData --- gatewayservice/gateway-service.js | 12 +++++++++--- webapp/src/stores/playing-store.ts | 14 ++++++++++++-- wikidata_service/Dockerfile | 2 -- .../WikiDataTest/Properties/launchSettings.json | 2 +- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index bb3a7c4..5ee4515 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -51,14 +51,20 @@ app.post('/edituser', async (req, res) => { } }); -app.get('/WikiData/GetCapitalsQuestions', async (_req, res) => { +app.get('/GetCapitalsQuestions', async (_req, res) => { try { // Forward the edit user request to the user service console.log(process.env.WIKIDATA_SERVICE_URL); - const wikiResponse = await axios.get(wikidataServiceUrl + '/WikiData/GetCapitalsQuestions'); - res.json(wikiResponse.data); + const wikiResponse = await axios.get(wikidataServiceUrl + '/WikiData/GetCapitalsQuestions', { timeout: 5000 }); + if (wikiResponse.status !== 200) { + console.error('Error with the wikidata service:', wikiResponse.status); + res.status(wikiResponse.status).json({ error: 'Error with the wikidata service' }); + } else { + res.json(wikiResponse.data); + } } catch (error) { console.error(error); + res.status(500).json({ error: 'Error with the gateway service' }); } }); diff --git a/webapp/src/stores/playing-store.ts b/webapp/src/stores/playing-store.ts index 92c8cf1..6f0133e 100644 --- a/webapp/src/stores/playing-store.ts +++ b/webapp/src/stores/playing-store.ts @@ -61,15 +61,25 @@ const API_URL = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; export const retrieveQuestions = async () => { try { - let response = await axios.get(`${API_URL}/WikiData/GetCapitalsQuestions`); + let response = await axios.get(`${API_URL}/GetCapitalsQuestions`); console.log('response:', response); - return response.data.json(); + return response.data; } catch (error) { console.error('There was a problem with the questions:', error); return []; } }; +// const retrieveQuestionss = () => { +// console.log(`${API_URL}`); +// return fetch(`${API_URL}/WikiData/GetCapitalsQuestions`) +// .then((response) => response.json()) +// .catch((error) => { +// console.error('There was a problem with the questions:', error); +// return []; // Return an empty array in case of an error +// }); +// }; + export const useGameQuestions = create((set) => ({ questions: [], setQuestions: (questions: any[]) => set({ questions: questions }), diff --git a/wikidata_service/Dockerfile b/wikidata_service/Dockerfile index c3de0e2..ec812db 100644 --- a/wikidata_service/Dockerfile +++ b/wikidata_service/Dockerfile @@ -1,7 +1,5 @@ FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base WORKDIR /app -EXPOSE 80 -EXPOSE 443 FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build ARG BUILD_CONFIGURATION=Release diff --git a/wikidata_service/WikiDataTest/Properties/launchSettings.json b/wikidata_service/WikiDataTest/Properties/launchSettings.json index 730a8b3..0a8ea3d 100644 --- a/wikidata_service/WikiDataTest/Properties/launchSettings.json +++ b/wikidata_service/WikiDataTest/Properties/launchSettings.json @@ -8,7 +8,7 @@ "ASPNETCORE_ENVIRONMENT": "Development" }, "dotnetRunMessages": true, - "applicationUrl": "http://localhost:7259;http://localhost:5276" + "applicationUrl": "http://localhost:7259" }, "IIS Express": { "commandName": "IISExpress",