Skip to content

Commit

Permalink
Arreglos para stats
Browse files Browse the repository at this point in the history
  • Loading branch information
CANCI0 committed Mar 11, 2024
1 parent 04c3a6c commit 1854397
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
15 changes: 8 additions & 7 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ 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 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 @@ -71,7 +71,9 @@ app.get("/questions", 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);
const statsResponse = await axios.get(statsServiceUrl + "/stats", {
params: req.query,
});
res.json(statsResponse.data);
} catch (error) {
res
Expand All @@ -98,10 +100,9 @@ app.post("/saveGame", async (req, res) => {
app.get("/getstats", async (req, res) => {
try {
// Forward the stats request to the stats service
const statsResponse = await axios.get(
userServiceUrl + "/getstats",
req.body
);
const statsResponse = await axios.get(userServiceUrl + "/getstats", {
params: req.query,
});
res.json(statsResponse.data);
} catch (error) {
res
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/pages/Clasico/Clasico.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Footer from "../../components/Footer/Footer.js";

const JuegoPreguntas = () => {
const URL = process.env.REACT_APP_API_ENDPOINT || "http://localhost:8000"

const [isLoading, setIsLoading] = useState(true);
const [indicePregunta, setIndicePregunta] = useState(0);
const [puntuacion, setPuntuacion] = useState(0);
Expand Down Expand Up @@ -121,7 +122,7 @@ const JuegoPreguntas = () => {
avgTime: tiempoMedio,
};

const response = await fetch("http://localhost:8001/userSaveGame", {
const response = await fetch(URL + "/userSaveGame", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
4 changes: 3 additions & 1 deletion webapp/src/pages/Stats/Stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import Footer from "../../components/Footer/Footer.js";
import "./Stats.css";

const Stats = () => {
const gatewayUrl = process.env.GATEWAY_SERVICE_URL || "http://localhost:8000";

const [username, setUsername] = useState(localStorage.username);
const [stats, setStats] = useState(null);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState(null);

useEffect(() => {
const delayDebounceFn = setTimeout(() => {
fetch(`http://localhost:8001/getstats?user=${username}`)
fetch(gatewayUrl + `/getstats?user=${username}`)
.then((response) => response.json())
.then((data) => {
setStats(data);
Expand Down

0 comments on commit 1854397

Please sign in to comment.