Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
hu8813 committed Apr 2, 2024
1 parent 9f5497b commit cd5bd32
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 5 additions & 2 deletions frontend/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ initialize();




const handleLocation = async () => {
const path = window.location.hash || '#';
let path = window.location.hash || '#';
const questionMarkIndex = path.indexOf('?');
if (questionMarkIndex !== -1) {
path = path.slice(0, questionMarkIndex);
}
const route = routes[path] || routes[404];
const html = await fetch(route).then((data) => data.text());
document.getElementById("app").innerHTML = html;
Expand Down
15 changes: 13 additions & 2 deletions frontend/views/return.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
</head>
<body>
<script>
const currentURL = window.location.href;
let backendURL = "";
const privateIPRegex = /^(10\.|192\.168\.|172\.(1[6-9]|2[0-9]|3[0-1])\.)/;
if (currentURL.includes("localhost") || currentURL.includes("127.0.0.1")) {
backendURL = "http://localhost:8000";
} else if (privateIPRegex.test(currentURL)) {
backendURL = "http://localhost:8000";
} else {
backendURL = "https://pong42.azurewebsites.net";
}


document.addEventListener("DOMContentLoaded", async function() {
const locationSearch = window.location.search;
const params = new URLSearchParams(locationSearch);
Expand All @@ -28,12 +40,11 @@
localStorage.setItem("userScore", userData.score);
localStorage.setItem("userEmail", userData.email);


window.location.href = "/";
} catch (error) {
console.error("Error fetching user info:", error);

}
window.location.href = "/";
}
});
</script>
Expand Down

0 comments on commit cd5bd32

Please sign in to comment.