Support vite base URL

This commit is contained in:
fk 2023-12-26 21:11:55 +01:00
parent 63ead7afb7
commit 1a530dddf0
7 changed files with 20 additions and 10 deletions

View file

@ -1,6 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html style="background: #0f0f0f" lang="en" > <html style="background: #0f0f0f" lang="en" >
<head> <head>
<base href="%BASE_URL%"/>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" /> <meta name="viewport" content="width=device-width,initial-scale=1.0" />

View file

@ -49,7 +49,7 @@ export default {
mounted() { mounted() {
//TODO: Add Server Side check //TODO: Add Server Side check
if (this.getAuthToken()) { if (this.getAuthToken()) {
this.$router.push("/"); this.$router.push(import.meta.env.BASE_URL);
} }
}, },
activated() { activated() {
@ -67,7 +67,7 @@ export default {
}).then(resp => { }).then(resp => {
if (resp.token) { if (resp.token) {
this.setPreference("authToken" + this.hashCode(this.authApiUrl()), resp.token); this.setPreference("authToken" + this.hashCode(this.authApiUrl()), resp.token);
window.location = "/"; // done to bypass cache window.location = import.meta.env.BASE_URL; // done to bypass cache
} else alert(resp.error); } else alert(resp.error);
}); });
}, },

View file

@ -131,7 +131,7 @@ export default {
searchText: "", searchText: "",
suggestionsVisible: false, suggestionsVisible: false,
showTopNav: false, showTopNav: false,
homePagePath: "/", homePagePath: import.meta.env.BASE_URL,
registrationDisabled: false, registrationDisabled: false,
}; };
}, },

View file

@ -1,7 +1,11 @@
<script setup>
const homeUrl = import.meta.env.BASE_URL;
</script>
<template> <template>
<div class="min-h-[88vh] flex flex-col items-center justify-center"> <div class="min-h-[88vh] flex flex-col items-center justify-center">
<h1 class="font-bold !text-9xl">404</h1> <h1 class="font-bold !text-9xl">404</h1>
<h2 v-t="'info.page_not_found'" class="!text-2xl" /> <h2 v-t="'info.page_not_found'" class="!text-2xl" />
<a v-t="'actions.back_to_home'" class="btn mt-16" href="/" /> <a v-t="'actions.back_to_home'" class="btn mt-16" :href="homeUrl" />
</div> </div>
</template> </template>

View file

@ -655,14 +655,14 @@ export default {
// reset the auth token // reset the auth token
localStorage.removeItem("authToken" + this.hashCode(this.authApiUrl())); localStorage.removeItem("authToken" + this.hashCode(this.authApiUrl()));
// redirect to trending page // redirect to trending page
window.location = "/"; window.location = import.meta.env.BASE_URL;
}, },
resetPreferences() { resetPreferences() {
this.showConfirmResetPrefsDialog = false; this.showConfirmResetPrefsDialog = false;
// clear the local storage // clear the local storage
localStorage.clear(); localStorage.clear();
// redirect to the home page // redirect to the home page
window.location = "/"; window.location = import.meta.env.BASE_URL;
}, },
async invalidateSession() { async invalidateSession() {
this.fetchJson(this.authApiUrl() + "/logout", null, { this.fetchJson(this.authApiUrl() + "/logout", null, {

View file

@ -81,7 +81,7 @@ export default {
mounted() { mounted() {
//TODO: Add Server Side check //TODO: Add Server Side check
if (this.getAuthToken()) { if (this.getAuthToken()) {
this.$router.push("/"); this.$router.push(import.meta.env.BASE_URL);
} }
}, },
activated() { activated() {
@ -107,7 +107,7 @@ export default {
}).then(resp => { }).then(resp => {
if (resp.token) { if (resp.token) {
this.setPreference("authToken" + this.hashCode(this.authApiUrl()), resp.token); this.setPreference("authToken" + this.hashCode(this.authApiUrl()), resp.token);
window.location = "/"; // done to bypass cache window.location = import.meta.env.BASE_URL; // done to bypass cache
} else alert(resp.error); } else alert(resp.error);
}); });
}, },

View file

@ -23,7 +23,12 @@ export default {
}; };
}, },
mounted() { mounted() {
if (this.$route.path == "/" && this.getPreferenceString("homepage", "trending") == "feed") return; if (
this.$route.path == import.meta.env.BASE_URL &&
this.getPreferenceString("homepage", "trending") == "feed"
) {
return;
}
let region = this.getPreferenceString("region", "US"); let region = this.getPreferenceString("region", "US");
this.fetchTrending(region).then(videos => { this.fetchTrending(region).then(videos => {
@ -35,7 +40,7 @@ export default {
activated() { activated() {
document.title = this.$t("titles.trending") + " - Piped"; document.title = this.$t("titles.trending") + " - Piped";
if (this.videos.length > 0) this.updateWatched(this.videos); if (this.videos.length > 0) this.updateWatched(this.videos);
if (this.$route.path == "/") { if (this.$route.path == import.meta.env.BASE_URL) {
let homepage = this.getHomePage(this); let homepage = this.getHomePage(this);
if (homepage !== undefined) this.$router.push(homepage); if (homepage !== undefined) this.$router.push(homepage);
} }