Skip to content

Commit

Permalink
Merge pull request #115 from Arquisoft/build_sergiot
Browse files Browse the repository at this point in the history
Fixing routing issues
  • Loading branch information
sergiollende authored Mar 14, 2024
2 parents edb198b + 611e8f3 commit 5dfcc81
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
19 changes: 15 additions & 4 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ app.get('/health', (_req, res) => {
app.post('/login', async (req, res) => {
try {
// Forward the login request to the authentication service
const authResponse = await axios.post(authServiceUrl+'/auth/login', req.body);
const authResponse = await axios.post(authServiceUrl+'/login', req.body);
res.json(authResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
Expand All @@ -35,22 +35,33 @@ app.post('/login', async (req, res) => {
app.post('/adduser', async (req, res) => {
try {
// Forward the add user request to the user service
const userResponse = await axios.post(userServiceUrl+'/user/adduser', req.body);
const userResponse = await axios.post(userServiceUrl+'/adduser', req.body);
res.json(userResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});

app.get('/WikiData/GetCapitalQuestions', async (_req, res) => {
app.post('/edituser', async (req, res) => {
try {
const userResponse = await axios.get(wikidataServiceUrl+'/WikiData/GetCapitalQuestions', req.body);
// Forward the edit user request to the user service
const userResponse = await axios.post(userServiceUrl+'/edituser', req.body);
res.json(userResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});

app.get('/WikiData/GetCapitalsQuestions', async (_req, res) => {
try {
// Forward the edit user request to the user service
const wikiResponse = await axios.get(wikidataServiceUrl+'/WikiData/GetCapitalsQuestions', req.body);
res.json(wikiResponse.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
6 changes: 3 additions & 3 deletions webapp/src/services/auth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const loginWithToken = () => {

export const login = async (username: string, password: string)=> {
try {
const response = await axios.post(`${API_URL}/auth/login`, { username, password });
const response = await axios.post(`${API_URL}/login`, { username, password });
//const response = await axios.post("http://localhost:8002/auth/login", { username, password });
const token = response.data.token;
console.log('token:', token);
Expand All @@ -37,7 +37,7 @@ export const login = async (username: string, password: string)=> {

export const register = async (email:string, username: string, password: string) => {
try {
const response = await axios.post(`${API_URL}/user/adduser`, { username, password, email });
const response = await axios.post(`${API_URL}/adduser`, { username, password, email });
console.log('response:', response);
const name = response.data;
return name;
Expand All @@ -50,7 +50,7 @@ export const register = async (email:string, username: string, password: string)
export const updateStats = async (questions_answered: number, correctly_answered_questions: number) => {
const username = getUsername();
try {
await axios.post(`${API_URL}/user/editUser`, { username, questions_answered, correctly_answered_questions });
await axios.post(`${API_URL}/edituser`, { username, questions_answered, correctly_answered_questions });
updateStatsState(questions_answered, correctly_answered_questions);
return true;
} catch (error) {
Expand Down

0 comments on commit 5dfcc81

Please sign in to comment.