Skip to content

Commit

Permalink
Stats get and post added to gateway service
Browse files Browse the repository at this point in the history
  • Loading branch information
iyanfdezz committed Mar 2, 2024
1 parent 46bdad3 commit 8327b73
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const port = 8000;
const authServiceUrl = process.env.AUTH_SERVICE_URL || 'http://localhost:8002';
const userServiceUrl = process.env.USER_SERVICE_URL || 'http://localhost:8001';
const questionServiceUrl = process.env.QUESTION_SERVICE_URL || 'http://localhost:8003';
const statsServiceUrl = process.env.AUTH_SERVICE_URL || 'http://localhost:8004';

app.use(cors());
app.use(express.json());
Expand Down Expand Up @@ -52,6 +53,26 @@ app.get('/randomQuestion', async (req, res) => {
}
});

app.get('/stats', async (req, res) => {
try {
// Forward the stats request to the stats service
const statsResponse = await axios.get(statsServiceUrl+'/stats', req.body);
res.json(statsResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});

app.post('/saveGame', async (req, res) => {
try {
// Forward the save game request to the stats service
const gameResponse = await axios.post(statsServiceUrl+'/saveGame', req.body);
res.json(gameResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});

// Start the gateway service
const server = app.listen(port, () => {
console.log(`Gateway Service listening at http://localhost:${port}`);
Expand Down
1 change: 1 addition & 0 deletions webapp/src/pages/Stats/Stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const Stats = () => {
<h2>Error: {error}</h2>
<p>Por favor compruebe si los valores del formulario son correctos e inténtelo de nuevo</p>
</div>
<Footer />
</>
}

Expand Down

0 comments on commit 8327b73

Please sign in to comment.