Skip to content

Commit 84b2637

Browse files
authored
feat: allow setting API, proxy, and frontend URLs at build time (#3284)
1 parent f033ee7 commit 84b2637

File tree

9 files changed

+28
-15
lines changed

9 files changed

+28
-15
lines changed

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
VITE_PIPED_API=https://pipedapi.kavin.rocks
2+
VITE_PIPED_PROXY=https://pipedproxy.kavin.rocks
3+
VITE_PIPED_INSTANCES=https://piped-instances.kavin.rocks/

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html style="background: #0f0f0f" lang="en" >
33
<head>
4+
<base href="%BASE_URL%"/>
45
<meta charset="utf-8" />
56
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
67
<meta name="viewport" content="width=device-width,initial-scale=1.0" />

src/components/LoginPage.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default {
5151
mounted() {
5252
//TODO: Add Server Side check
5353
if (this.getAuthToken()) {
54-
this.$router.push("/");
54+
this.$router.push(import.meta.env.BASE_URL);
5555
}
5656
},
5757
activated() {
@@ -69,7 +69,7 @@ export default {
6969
}).then(resp => {
7070
if (resp.token) {
7171
this.setPreference("authToken" + this.hashCode(this.authApiUrl()), resp.token);
72-
window.location = "/"; // done to bypass cache
72+
window.location = import.meta.env.BASE_URL; // done to bypass cache
7373
} else alert(resp.error);
7474
});
7575
},

src/components/NavBar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export default {
131131
searchText: "",
132132
suggestionsVisible: false,
133133
showTopNav: false,
134-
homePagePath: "/",
134+
homePagePath: import.meta.env.BASE_URL,
135135
registrationDisabled: false,
136136
};
137137
},

src/components/PageNotFound.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
<script setup>
2+
const homeUrl = import.meta.env.BASE_URL;
3+
</script>
4+
15
<template>
26
<div class="min-h-[88vh] flex flex-col items-center justify-center">
37
<h1 class="font-bold !text-9xl">404</h1>
48
<h2 v-t="'info.page_not_found'" class="!text-2xl" />
5-
<a v-t="'actions.back_to_home'" class="btn mt-16" href="/" />
9+
<a v-t="'actions.back_to_home'" class="btn mt-16" :href="homeUrl" />
610
</div>
711
</template>

src/components/PreferencesPage.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ export default {
504504
async mounted() {
505505
if (Object.keys(this.$route.query).length > 0) this.$router.replace({ query: {} });
506506
507-
this.fetchJson("https://piped-instances.kavin.rocks/").then(resp => {
507+
this.fetchJson(import.meta.env.VITE_PIPED_INSTANCES).then(resp => {
508508
this.instances = resp;
509509
if (!this.instances.some(instance => instance.api_url == this.apiUrl()))
510510
this.instances.push({
@@ -517,7 +517,7 @@ export default {
517517
});
518518
519519
if (this.testLocalStorage) {
520-
this.selectedInstance = this.getPreferenceString("instance", "https://pipedapi.kavin.rocks");
520+
this.selectedInstance = this.getPreferenceString("instance", import.meta.env.VITE_PIPED_API);
521521
this.authInstance = this.getPreferenceBoolean("authInstance", false);
522522
this.selectedAuthInstance = this.getPreferenceString("auth_instance_url", this.selectedInstance);
523523
@@ -655,14 +655,14 @@ export default {
655655
// reset the auth token
656656
localStorage.removeItem("authToken" + this.hashCode(this.authApiUrl()));
657657
// redirect to trending page
658-
window.location = "/";
658+
window.location = import.meta.env.BASE_URL;
659659
},
660660
resetPreferences() {
661661
this.showConfirmResetPrefsDialog = false;
662662
// clear the local storage
663663
localStorage.clear();
664664
// redirect to the home page
665-
window.location = "/";
665+
window.location = import.meta.env.BASE_URL;
666666
},
667667
async invalidateSession() {
668668
this.fetchJson(this.authApiUrl() + "/logout", null, {

src/components/RegisterPage.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default {
8383
mounted() {
8484
//TODO: Add Server Side check
8585
if (this.getAuthToken()) {
86-
this.$router.push("/");
86+
this.$router.push(import.meta.env.BASE_URL);
8787
}
8888
},
8989
activated() {
@@ -109,7 +109,7 @@ export default {
109109
}).then(resp => {
110110
if (resp.token) {
111111
this.setPreference("authToken" + this.hashCode(this.authApiUrl()), resp.token);
112-
window.location = "/"; // done to bypass cache
112+
window.location = import.meta.env.BASE_URL; // done to bypass cache
113113
} else alert(resp.error);
114114
});
115115
},

src/components/TrendingPage.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ export default {
2323
};
2424
},
2525
mounted() {
26-
if (this.$route.path == "/" && this.getPreferenceString("homepage", "trending") == "feed") return;
26+
if (
27+
this.$route.path == import.meta.env.BASE_URL &&
28+
this.getPreferenceString("homepage", "trending") == "feed"
29+
) {
30+
return;
31+
}
2732
let region = this.getPreferenceString("region", "US");
2833
2934
this.fetchTrending(region).then(videos => {
@@ -35,7 +40,7 @@ export default {
3540
activated() {
3641
document.title = this.$t("titles.trending") + " - Piped";
3742
if (this.videos.length > 0) this.updateWatched(this.videos);
38-
if (this.$route.path == "/") {
43+
if (this.$route.path == import.meta.env.BASE_URL) {
3944
let homepage = this.getHomePage(this);
4045
if (homepage !== undefined) this.$router.push(homepage);
4146
}

src/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const mixin = {
117117
} else return defaultVal;
118118
},
119119
apiUrl() {
120-
return this.getPreferenceString("instance", "https://pipedapi.kavin.rocks");
120+
return this.getPreferenceString("instance", import.meta.env.VITE_PIPED_API);
121121
},
122122
authApiUrl() {
123123
if (this.getPreferenceBoolean("authInstance", false)) {
@@ -347,7 +347,7 @@ const mixin = {
347347
id: playlistId,
348348
name: name,
349349
description: "",
350-
thumbnail: "https://pipedproxy.kavin.rocks/?host=i.ytimg.com",
350+
thumbnail: import.meta.env.VITE_PIPED_PROXY + "/?host=i.ytimg.com",
351351
videoIds: "[]", // empty list
352352
});
353353
return { playlistId: playlistId };
@@ -471,7 +471,7 @@ const mixin = {
471471
const videoIds = JSON.parse(playlist.videoIds);
472472
videoIds.splice(index, 1);
473473
playlist.videoIds = JSON.stringify(videoIds);
474-
if (videoIds.length == 0) playlist.thumbnail = "https://pipedproxy.kavin.rocks/?host=i.ytimg.com";
474+
if (videoIds.length == 0) playlist.thumbnail = import.meta.env.VITE_PIPED_PROXY + "/?host=i.ytimg.com";
475475
this.createOrUpdateLocalPlaylist(playlist);
476476
return { message: "ok" };
477477
}

0 commit comments

Comments
 (0)