forked from spacebar/SplatNet
polish up index.html & add TODOs
This commit is contained in:
parent
343de86101
commit
4a42bbd8c7
3 changed files with 54 additions and 11 deletions
49
autoredirect.js
Normal file
49
autoredirect.js
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
const apiBase = CONFIG.API_BASE_URL;
|
||||||
|
const friendListUrl = "/friend_list/index.html";
|
||||||
|
|
||||||
|
async function checkExistingSession() {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${apiBase}/api/v1/users/me`, {
|
||||||
|
method: 'GET',
|
||||||
|
credentials: 'include'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
renderSeamlessPage();
|
||||||
|
} else {
|
||||||
|
window.location.href = "/sign_in";
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Auth check failed:", err);
|
||||||
|
window.location.href = "/sign_in";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function renderSeamlessPage() {
|
||||||
|
try {
|
||||||
|
const res = await fetch(friendListUrl);
|
||||||
|
if (!res.ok) throw new Error("Failed to fetch friend_list/index.html");
|
||||||
|
let html = await res.text();
|
||||||
|
html = html.replace(/src="\.\.\//g, 'src="/');
|
||||||
|
html = html.replace(/href="\.\.\//g, 'href="/');
|
||||||
|
const baseTag = `<base href="/friend_list/">`;
|
||||||
|
|
||||||
|
if (html.includes('<head>')) {
|
||||||
|
html = html.replace('<head>', `<head>\n ${baseTag}`);
|
||||||
|
} else {
|
||||||
|
//fallback
|
||||||
|
html = baseTag + html;
|
||||||
|
}
|
||||||
|
document.open();
|
||||||
|
document.write(html);
|
||||||
|
document.close();
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Seamless render failed, falling back to redirect:", err);
|
||||||
|
window.location.href = "/friend_list/index.html";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkExistingSession();
|
||||||
|
});
|
||||||
14
index.html
14
index.html
|
|
@ -1,11 +1,3 @@
|
||||||
<!DOCTYPE html>
|
<script src="https://code.jquery.com/jquery-4.0.0.min.js"></script>
|
||||||
<html lang="en">
|
<script src="config.js"></script>
|
||||||
<head>
|
<script src="autoredirect.js"></script>
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta http-equiv="refresh" content="3;url=/sign_in/">
|
|
||||||
<title>temp page for now!!!</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<p>If you are not redirected automatically, <a href="/sign_in/">click here</a>.</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
//TODO: Migrate to jQuery 4.0, currently left unchanged as of now to avoid breaking changes
|
||||||
|
|
||||||
/*! jQuery v1.9.1 | (c) 2005, 2012 jQuery Foundation, Inc. | jquery.org/license
|
/*! jQuery v1.9.1 | (c) 2005, 2012 jQuery Foundation, Inc. | jquery.org/license
|
||||||
//@ sourceMappingURL=jquery.min.map
|
//@ sourceMappingURL=jquery.min.map
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue