Skip to content

Commit

Permalink
endpoint in gateway service
Browse files Browse the repository at this point in the history
  • Loading branch information
pelazas committed Feb 23, 2024
1 parent acfcda9 commit af892d7
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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 qgServiceUrl = process.env.GQ_SERVICE_URL || 'http://localhost:8003';

app.use(cors());
app.use(express.json());
Expand Down Expand Up @@ -41,6 +42,29 @@ app.post('/adduser', async (req, res) => {
}
});

app.get('/populationQuestion', async (req, res) => {
try {
const country = req.query.country.toLowerCase();

// Forward the population question request to the user service
const endpoint = `${qgServiceUrl}/${country}Population`;
console.log(endpoint);

if (country !== 'spain' && country !== 'usa') {
console.log(country);
res.status(400).json({ error: 'Country not supported', message: 'Please use a valid country' });
return;
}

const populationResponse = await axios.get(endpoint);
res.json(populationResponse.data);
} catch (error) {
console.error('Error in /populationQuestion:', error);
res.status(500).json({ error: 'Internal server error' });
}
});


// Start the gateway service
const server = app.listen(port, () => {
console.log(`Gateway Service listening at http://localhost:${port}`);
Expand Down

0 comments on commit af892d7

Please sign in to comment.