From 63ead7afb715fccc98fc26e41ff956c4187764dd Mon Sep 17 00:00:00 2001 From: fk <2378306+fkrull@users.noreply.github.com> Date: Tue, 26 Dec 2023 19:30:28 +0100 Subject: [PATCH] Make backend URLs overridable with env vars at build time --- .env | 3 +++ src/components/PreferencesPage.vue | 4 ++-- src/main.js | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 00000000..ddba8b7a --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +VITE_PIPED_API=https://pipedapi.kavin.rocks +VITE_PIPED_PROXY=https://pipedproxy.kavin.rocks +VITE_PIPED_INSTANCES=https://piped-instances.kavin.rocks/ diff --git a/src/components/PreferencesPage.vue b/src/components/PreferencesPage.vue index 059e2399..7b271a9e 100644 --- a/src/components/PreferencesPage.vue +++ b/src/components/PreferencesPage.vue @@ -504,7 +504,7 @@ export default { async mounted() { if (Object.keys(this.$route.query).length > 0) this.$router.replace({ query: {} }); - this.fetchJson("https://piped-instances.kavin.rocks/").then(resp => { + this.fetchJson(import.meta.env.VITE_PIPED_INSTANCES).then(resp => { this.instances = resp; if (!this.instances.some(instance => instance.api_url == this.apiUrl())) this.instances.push({ @@ -517,7 +517,7 @@ export default { }); if (this.testLocalStorage) { - this.selectedInstance = this.getPreferenceString("instance", "https://pipedapi.kavin.rocks"); + this.selectedInstance = this.getPreferenceString("instance", import.meta.env.VITE_PIPED_API); this.authInstance = this.getPreferenceBoolean("authInstance", false); this.selectedAuthInstance = this.getPreferenceString("auth_instance_url", this.selectedInstance); diff --git a/src/main.js b/src/main.js index 9d6f8382..f1a563c2 100644 --- a/src/main.js +++ b/src/main.js @@ -171,7 +171,7 @@ const mixin = { } else return defaultVal; }, apiUrl() { - return this.getPreferenceString("instance", "https://pipedapi.kavin.rocks"); + return this.getPreferenceString("instance", import.meta.env.VITE_PIPED_API); }, authApiUrl() { if (this.getPreferenceBoolean("authInstance", false)) { @@ -379,7 +379,7 @@ const mixin = { id: playlistId, name: name, description: "", - thumbnail: "https://pipedproxy.kavin.rocks/?host=i.ytimg.com", + thumbnail: import.meta.env.VITE_PIPED_PROXY + "/?host=i.ytimg.com", videoIds: "[]", // empty list }); return { playlistId: playlistId }; @@ -503,7 +503,7 @@ const mixin = { const videoIds = JSON.parse(playlist.videoIds); videoIds.splice(index, 1); playlist.videoIds = JSON.stringify(videoIds); - if (videoIds.length == 0) playlist.thumbnail = "https://pipedproxy.kavin.rocks/?host=i.ytimg.com"; + if (videoIds.length == 0) playlist.thumbnail = import.meta.env.VITE_PIPED_PROXY + "/?host=i.ytimg.com"; this.createOrUpdateLocalPlaylist(playlist); return { message: "ok" }; }