From 2698ec42842863b33f5515c32f8bf0faa0816393 Mon Sep 17 00:00:00 2001 From: Manuel Kasper Date: Wed, 3 Aug 2022 10:37:10 +0200 Subject: [PATCH] Make api and images URL configurable via environment variables --- .env | 4 ++++ src/components/EditAlert.vue | 2 +- src/components/EditSpot.vue | 2 +- src/components/NearbySummitsList.vue | 2 +- src/components/SolarData.vue | 2 +- src/components/SwisstopoInfo.vue | 2 +- src/mixins/api.js | 10 +++++----- src/mixins/mapstyle.js | 2 +- src/mixins/photos.js | 4 ++-- src/mixins/sotadb.js | 2 +- src/store.js | 4 ++-- src/views/Activator.vue | 2 +- src/views/Activators.vue | 2 +- src/views/Association.vue | 4 ++-- src/views/AssociationList.vue | 2 +- src/views/Map.vue | 6 +++--- src/views/NewPhotos.vue | 4 ++-- src/views/Region.vue | 6 +++--- src/views/SearchAnything.vue | 4 ++-- src/views/SolarHistory.vue | 2 +- src/views/Summit.vue | 10 +++++----- 21 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..aae33bb --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +VUE_APP_API_URL="https://api.sotl.as" +VUE_APP_WSS_URL="wss://api.sotl.as" +VUE_APP_PHOTOS_URL="https://images.sotl.as/photos" +VUE_APP_PHOTOS_ORIGINAL_URL="https://sotlas-photos.s3.eu-central-003.backblazeb2.com/original" diff --git a/src/components/EditAlert.vue b/src/components/EditAlert.vue index 18d3278..0ae884f 100644 --- a/src/components/EditAlert.vue +++ b/src/components/EditAlert.vue @@ -154,7 +154,7 @@ export default { if (matches) { this.summitCode = (matches[1] + '/' + matches[2] + '-' + matches[3]).toUpperCase() this.summitLoading = true - axios.get('https://api.sotl.as/summits/' + this.summitCode) + axios.get(process.env.VUE_APP_API_URL + '/summits/' + this.summitCode) .then(response => { this.summitLoading = false this.summitInvalid = false diff --git a/src/components/EditSpot.vue b/src/components/EditSpot.vue index 3aa1abd..8db9891 100644 --- a/src/components/EditSpot.vue +++ b/src/components/EditSpot.vue @@ -141,7 +141,7 @@ export default { if (matches) { this.summitCode = (matches[1] + '/' + matches[2] + '-' + matches[3]).toUpperCase() this.summitLoading = true - axios.get('https://api.sotl.as/summits/' + this.summitCode) + axios.get(process.env.VUE_APP_API_URL + '/summits/' + this.summitCode) .then(response => { this.summitLoading = false this.summitInvalid = false diff --git a/src/components/NearbySummitsList.vue b/src/components/NearbySummitsList.vue index 4edcc6b..004431b 100644 --- a/src/components/NearbySummitsList.vue +++ b/src/components/NearbySummitsList.vue @@ -28,7 +28,7 @@ export default { this.loading = true navigator.geolocation.getCurrentPosition( position => { - axios.get('https://api.sotl.as/summits/near', { params: { lat: position.coords.latitude, lon: position.coords.longitude, limit: 5, maxDistance: 100000 } }) + axios.get(process.env.VUE_APP_API_URL + '/summits/near', { params: { lat: position.coords.latitude, lon: position.coords.longitude, limit: 5, maxDistance: 100000 } }) .then(response => { if (response.data.length === 0) { alert('No summits within 100 km.') diff --git a/src/components/SolarData.vue b/src/components/SolarData.vue index 50366bb..dd12996 100644 --- a/src/components/SolarData.vue +++ b/src/components/SolarData.vue @@ -36,7 +36,7 @@ export default { }, methods: { loadSolarData () { - axios.get('https://api.sotl.as/solardata/latest') + axios.get(process.env.VUE_APP_API_URL + '/solardata/latest') .then(response => { this.latest = response.data }) diff --git a/src/components/SwisstopoInfo.vue b/src/components/SwisstopoInfo.vue index 79ce598..2196086 100644 --- a/src/components/SwisstopoInfo.vue +++ b/src/components/SwisstopoInfo.vue @@ -38,7 +38,7 @@ export default { mounted () { if (!localStorage.getItem('swisstopoInfoShown')) { // Check if we are in Switzerland - axios.get('https://api.sotl.as/my_country') + axios.get(process.env.VUE_APP_API_URL + '/my_country') .then(response => { if (response.data.country === 'CH') { this.active = true diff --git a/src/mixins/api.js b/src/mixins/api.js index 7d2cb04..b7124fc 100644 --- a/src/mixins/api.js +++ b/src/mixins/api.js @@ -5,7 +5,7 @@ export default { mixins: [ssoauth], methods: { loadActivations (callsign) { - return axios.get('https://api.sotl.as/activations/' + callsign) + return axios.get(process.env.VUE_APP_API_URL + '/activations/' + callsign) .then(response => { return response.data }) @@ -13,20 +13,20 @@ export default { uploadPhoto (summitCode, file, progress, cancelToken) { let formData = new FormData() formData.append('photo', file) - return this.axiosAuth.post('https://api.sotl.as/photos/summits/' + summitCode + '/upload', formData, { + return this.axiosAuth.post(process.env.VUE_APP_API_URL + '/photos/summits/' + summitCode + '/upload', formData, { headers: { 'Content-Type': 'multipart/form-data' }, onUploadProgress: progress, cancelToken }) }, deletePhoto (summitCode, filename) { - return this.axiosAuth.delete('https://api.sotl.as/photos/summits/' + summitCode + '/' + filename) + return this.axiosAuth.delete(process.env.VUE_APP_API_URL + '/photos/summits/' + summitCode + '/' + filename) }, editPhoto (summitCode, filename, data) { - return this.axiosAuth.post('https://api.sotl.as/photos/summits/' + summitCode + '/' + filename, data) + return this.axiosAuth.post(process.env.VUE_APP_API_URL + '/photos/summits/' + summitCode + '/' + filename, data) }, reorderPhotos (summitCode, filenames) { - return this.axiosAuth.post('https://api.sotl.as/photos/summits/' + summitCode + '/reorder', { filenames }) + return this.axiosAuth.post(process.env.VUE_APP_API_URL + '/photos/summits/' + summitCode + '/reorder', { filenames }) } } } diff --git a/src/mixins/mapstyle.js b/src/mixins/mapstyle.js index 601204b..add04af 100644 --- a/src/mixins/mapstyle.js +++ b/src/mixins/mapstyle.js @@ -12,7 +12,7 @@ export default { if (mapServerOverride && mapServerOverride !== 'test') { this.mapServer = mapServerOverride } else { - axios.get('https://api.sotl.as/map_server') + axios.get(process.env.VUE_APP_API_URL + '/map_server') .then(response => { if (response.data.mapServer) { this.mapServer = response.data.mapServer diff --git a/src/mixins/photos.js b/src/mixins/photos.js index ceb7bc7..0db688d 100644 --- a/src/mixins/photos.js +++ b/src/mixins/photos.js @@ -2,9 +2,9 @@ export default { methods: { photoSrc (photo, size) { if (size === 'original') { - return 'https://sotlas-photos.s3.eu-central-003.backblazeb2.com/original/' + photo.filename + return process.env.VUE_APP_PHOTOS_ORIGINAL_URL + '/' + photo.filename } else { - return 'https://images.sotl.as/photos/' + size + '/' + photo.filename.substring(0, 2) + '/' + photo.filename + return process.env.VUE_APP_PHOTOS_URL + '/' + size + '/' + photo.filename.substring(0, 2) + '/' + photo.filename } } } diff --git a/src/mixins/sotadb.js b/src/mixins/sotadb.js index 62dfe64..d477b6c 100644 --- a/src/mixins/sotadb.js +++ b/src/mixins/sotadb.js @@ -5,7 +5,7 @@ export default { mixins: [ssoauth], methods: { loadActivations (callsign) { - return axios.get('https://api.sotl.as/activations/' + callsign) + return axios.get(process.env.VUE_APP_API_URL + '/activations/' + callsign) .then(response => { return response.data }) diff --git a/src/store.js b/src/store.js index 1e184ff..de66eb9 100644 --- a/src/store.js +++ b/src/store.js @@ -200,7 +200,7 @@ function loadAlerts (noCache) { if (noCache) { params.noCache = 1 } - axios.get('https://api.sotl.as/alerts', { params }) + axios.get(process.env.VUE_APP_API_URL + '/alerts', { params }) .then(response => { store.commit('setAlerts', response.data) }) @@ -209,7 +209,7 @@ function loadAlerts (noCache) { loadAlerts(false) setInterval(loadAlerts, ALERT_UPDATE_INTERVAL) -Vue.use(VueNativeSock, 'wss://api.sotl.as/ws', { +Vue.use(VueNativeSock, process.env.VUE_APP_WSS_URL + '/ws', { format: 'json', store, reconnection: true, diff --git a/src/views/Activator.vue b/src/views/Activator.vue index 5b18041..6ae5aa5 100644 --- a/src/views/Activator.vue +++ b/src/views/Activator.vue @@ -340,7 +340,7 @@ export default { this.databaseError = false let loads = [] - axios.get('https://api.sotl.as/activators/' + this.callsign) + axios.get(process.env.VUE_APP_API_URL + '/activators/' + this.callsign) .then(response => { if (response) { this.activator = response.data diff --git a/src/views/Activators.vue b/src/views/Activators.vue index 5642518..1180056 100644 --- a/src/views/Activators.vue +++ b/src/views/Activators.vue @@ -63,7 +63,7 @@ export default { methods: { loadData () { this.loading = true - axios.get('https://api.sotl.as/activators/search', { params: { q: this.filter, skip: (this.curPage - 1) * this.perPage, limit: this.perPage, sort: this.sortField, sortDirection: this.sortDirection } }) + axios.get(process.env.VUE_APP_API_URL + '/activators/search', { params: { q: this.filter, skip: (this.curPage - 1) * this.perPage, limit: this.perPage, sort: this.sortField, sortDirection: this.sortDirection } }) .then(response => { this.activators = response.data.activators this.total = response.data.total diff --git a/src/views/Association.vue b/src/views/Association.vue index 643c516..1916c42 100644 --- a/src/views/Association.vue +++ b/src/views/Association.vue @@ -79,7 +79,7 @@ export default { }, loadAssociation () { this.loadingComponent = this.$buefy.loading.open({ canCancel: true }) - axios.get('https://api.sotl.as/associations/' + this.associationCode) + axios.get(process.env.VUE_APP_API_URL + '/associations/' + this.associationCode) .then(response => { this.association = response.data document.title = this.association.name + ' (' + this.associationCode + ') - SOTLAS' @@ -104,7 +104,7 @@ export default { }) }, exportUrlPrefix () { - return `https://api.sotl.as/geoexport/associations/${this.associationCode}` + return process.env.VUE_APP_API_URL + '/geoexport/associations/' + this.associationCode }, myActivationsPerRegion () { if (!this.$store.state.myActivatedSummits) { diff --git a/src/views/AssociationList.vue b/src/views/AssociationList.vue index 64d04eb..daf8e5b 100644 --- a/src/views/AssociationList.vue +++ b/src/views/AssociationList.vue @@ -49,7 +49,7 @@ export default { mounted () { document.title = 'Associations - SOTLAS' this.loadingComponent = this.$buefy.loading.open({ canCancel: true }) - axios.get('https://api.sotl.as/associations/all') + axios.get(process.env.VUE_APP_API_URL + '/associations/all') .then(response => { this.associations = response.data this.loadingComponent.close() diff --git a/src/views/Map.vue b/src/views/Map.vue index 472cc3a..aa58b9b 100644 --- a/src/views/Map.vue +++ b/src/views/Map.vue @@ -101,7 +101,7 @@ export default { } catch (e) {} this.showMap = true } else { - axios.get('https://api.sotl.as/my_coordinates') + axios.get(process.env.VUE_APP_API_URL + '/my_coordinates') .then(response => { if (response.data.latitude && response.data.longitude) { this.center = [response.data.longitude, response.data.latitude] @@ -346,7 +346,7 @@ export default { }) }, fetchSummit (summitCode) { - return axios.get('https://api.sotl.as/summits/' + summitCode) + return axios.get(process.env.VUE_APP_API_URL + '/summits/' + summitCode) .then(response => { let summit = response.data summit.photo = null @@ -354,7 +354,7 @@ export default { }) }, fetchAssociation (associationCode) { - return axios.get('https://api.sotl.as/associations/' + associationCode) + return axios.get(process.env.VUE_APP_API_URL + '/associations/' + associationCode) .then(response => { return response.data }) diff --git a/src/views/NewPhotos.vue b/src/views/NewPhotos.vue index 82ff09b..2601d04 100644 --- a/src/views/NewPhotos.vue +++ b/src/views/NewPhotos.vue @@ -64,7 +64,7 @@ export default { if (this.selectedAssociations.length > 0) { associations = this.selectedAssociations.join('|') } - axios.get('https://api.sotl.as/summits/recent_photos/' + associations + '/' + this.days, { params: recentPhotosParams }) + axios.get(process.env.VUE_APP_API_URL + '/summits/recent_photos/' + associations + '/' + this.days, { params: recentPhotosParams }) .then(response => { this.loadingComponent.close() this.summits = response.data.slice(0, -1) @@ -72,7 +72,7 @@ export default { }) }, loadAssociations () { - axios.get('https://api.sotl.as/associations/all') + axios.get(process.env.VUE_APP_API_URL + '/associations/all') .then(response => { this.associations = response.data }) diff --git a/src/views/Region.vue b/src/views/Region.vue index e8afb52..31fd3a3 100644 --- a/src/views/Region.vue +++ b/src/views/Region.vue @@ -74,7 +74,7 @@ export default { }) }, exportUrlPrefix () { - return `https://api.sotl.as/geoexport/regions/${this.regionCode}` + return process.env.VUE_APP_API_URL + '/geoexport/regions/' + this.regionCode }, exportUrlParams () { return (this.showInactive ? { inactive: 1 } : {}) @@ -125,7 +125,7 @@ export default { loadRegion () { let loads = [] this.loadingComponent = this.$buefy.loading.open({ canCancel: true }) - loads.push(axios.get('https://api.sotl.as/associations/' + this.associationCode) + loads.push(axios.get(process.env.VUE_APP_API_URL + '/associations/' + this.associationCode) .then(response => { this.association = response.data document.title = this.region.name + ' (' + this.associationCode + '/' + this.region.code + ') - SOTLAS' @@ -136,7 +136,7 @@ export default { } })) - loads.push(axios.get('https://api.sotl.as/regions/' + this.regionCode) + loads.push(axios.get(process.env.VUE_APP_API_URL + '/regions/' + this.regionCode) .then(response => { let now = moment() if (response.data.length === 0) { diff --git a/src/views/SearchAnything.vue b/src/views/SearchAnything.vue index ea92100..4f64cf9 100644 --- a/src/views/SearchAnything.vue +++ b/src/views/SearchAnything.vue @@ -78,12 +78,12 @@ export default { let loads = [] let q = this.$route.query.q.trim() this.loadingComponent = this.$buefy.loading.open({ canCancel: true }) - loads.push(axios.get('https://api.sotl.as/activators/search', { params: { q, limit: this.limit } }) + loads.push(axios.get(process.env.VUE_APP_API_URL + '/activators/search', { params: { q, limit: this.limit } }) .then(response => { this.activators = response.data.activators })) - loads.push(axios.get('https://api.sotl.as/summits/search', { params: { q, limit: this.limit } }) + loads.push(axios.get(process.env.VUE_APP_API_URL + '/summits/search', { params: { q, limit: this.limit } }) .then(response => { let now = moment() response.data.forEach(summit => { diff --git a/src/views/SolarHistory.vue b/src/views/SolarHistory.vue index 0a72f05..c8aff4f 100644 --- a/src/views/SolarHistory.vue +++ b/src/views/SolarHistory.vue @@ -26,7 +26,7 @@ export default { methods: { loadHistory () { // Fetch data from last 30 days - axios.get('https://api.sotl.as/solardata/history/720') + axios.get(process.env.VUE_APP_API_URL + '/solardata/history/720') .then(response => { this.loadingComponent.close() diff --git a/src/views/Summit.vue b/src/views/Summit.vue index 315dfd7..9dba32d 100644 --- a/src/views/Summit.vue +++ b/src/views/Summit.vue @@ -344,10 +344,10 @@ export default { } // Make a dummy POST to the summit URL to invalidate the browser's cache for future page loads - axios.post('https://api.sotl.as/summits/' + this.summitCode) + axios.post(process.env.VUE_APP_API_URL + '/summits/' + this.summitCode) } - loads.push(axios.get('https://api.sotl.as/summits/' + this.summitCode, options) + loads.push(axios.get(process.env.VUE_APP_API_URL + '/summits/' + this.summitCode, options) .then(response => { this.summit = response.data document.title = this.summit.name + ' (' + this.summit.code + ') - SOTLAS' @@ -358,7 +358,7 @@ export default { } })) - loads.push(axios.get('https://api.sotl.as/associations/' + this.summitCode.substr(0, this.summitCode.indexOf('/'))) + loads.push(axios.get(process.env.VUE_APP_API_URL + '/associations/' + this.summitCode.substr(0, this.summitCode.indexOf('/'))) .then(response => { this.association = response.data })) @@ -397,9 +397,9 @@ export default { this.loadingComponent = this.$buefy.loading.open({ canCancel: false }) // Make a dummy POST to the summit URL to invalidate the browser's cache for future page loads - axios.post('https://api.sotl.as/summits/' + this.summitCode) + axios.post(process.env.VUE_APP_API_URL + '/summits/' + this.summitCode) - axios.get('https://api.sotl.as/summits/' + this.summitCode, { params: { t: new Date().getTime() } }) + axios.get(process.env.VUE_APP_API_URL + '/summits/' + this.summitCode, { params: { t: new Date().getTime() } }) .then(response => { this.summit = response.data })