Make backend URLs overridable with env vars at build time

This commit is contained in:
fk 2023-12-26 19:30:28 +01:00
parent b01a16891a
commit 63ead7afb7
3 changed files with 8 additions and 5 deletions

3
.env Normal file
View file

@ -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/

View file

@ -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);

View file

@ -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" };
}