From 9b50895004ceb5c41dc54331c46548f21d9012cb Mon Sep 17 00:00:00 2001 From: Henrik Askjer <henrik.askjer@uib.no> Date: Wed, 29 Sep 2021 13:13:49 +0200 Subject: [PATCH] Organize endpoints and add stage parameter --- .env | 2 +- .env.dev_server | 3 ++- .env.local | 3 ++- .env.production | 3 ++- src/components/DictionaryView.vue | 37 ++++++++++++++++++------------- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/.env b/.env index 81e9a62e..441728f0 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -VUE_APP_API_PREFIX= +VUE_APP_SEARCH_ENDPOINT='https://oda.uib.no/opal/api/' \ No newline at end of file diff --git a/.env.dev_server b/.env.dev_server index ccec77e2..c096288f 100644 --- a/.env.dev_server +++ b/.env.dev_server @@ -1,2 +1,3 @@ NODE_ENV=production -VUE_APP_API_PREFIX= +VUE_APP_API_STAGE=dev +VUE_APP_ARTICLE_ENDPOINT='https://oda.uib.no/opal/dev/' \ No newline at end of file diff --git a/.env.local b/.env.local index d131c338..6750c0ed 100644 --- a/.env.local +++ b/.env.local @@ -1,3 +1,4 @@ -VUE_APP_API_PREFIX=https://dev.ordbok.uib.no +VUE_APP_API_STAGE=dev +VUE_APP_ARTICLE_ENDPOINT='https://oda.uib.no/opal/dev/' VUE_APP_VERSION_LABEL=LOCAL VUE_APP_RELEASE=test diff --git a/.env.production b/.env.production index af252fc9..be092e90 100644 --- a/.env.production +++ b/.env.production @@ -1,3 +1,4 @@ NODE_ENV=production VUE_APP_VERSION_LABEL=Beta -VUE_APP_API_PREFIX= +VUE_APP_API_STAGE=prod +VUE_APP_ARTICLE_ENDPOINT='https://oda.uib.no/opal/prod/' \ No newline at end of file diff --git a/src/components/DictionaryView.vue b/src/components/DictionaryView.vue index 601826e0..f80e2842 100644 --- a/src/components/DictionaryView.vue +++ b/src/components/DictionaryView.vue @@ -75,26 +75,33 @@ import Autocomplete from './Autocomplete.vue' import { setup } from 'axios-cache-adapter' +const SEARCH_ENDPOINT = process.env.VUE_APP_SEARCH_ENDPOINT +const ARTICLE_ENDPOINT= process.env.VUE_APP_ARTICLE_ENDPOINT +const API_STAGE = process.env.VUE_APP_API_STAGE + +console.log(SEARCH_ENDPOINT) +console.log(ARTICLE_ENDPOINT) +console.log(API_STAGE) + +const dicts = {'nob': 'Nynorskorboka', + 'bob': 'Bokmålsordboka', + 'bob,nob': 'ordbøkene'} + const oda_api = setup({ - baseURL: 'https://oda.uib.no/opal/api/', + baseURL: SEARCH_ENDPOINT, + params: {stage: API_STAGE}, cache: { maxAge: 15 * 60 * 1000, exclude: { query: false, - paths: ["articles"] + paths: ["articles"] // Disable caching for articles } } }) -const api_endpoint = process.env.VUE_APP_API_PREFIX + '/api/dict' - -const oda_dev = 'https://oda.uib.no/opal/dev' -const dicts = {'nob': 'Nynorskorboka', - 'bob': 'Bokmålsordboka', - 'bob,nob': 'ordbøkene'} function navigate_to_article(self, source) { let config = {headers: {}} @@ -102,7 +109,7 @@ function navigate_to_article(self, source) { if ((self.$route.query.nocache || '').toLowerCase() == 'true') { config.headers.cachebuster = Date.now() }*/ - axios.get(oda_dev + '/' + self.$route.params.lang + '/article/' + self.$route.params.id + ".json", config) + axios.get(ARTICLE_ENDPOINT + self.$route.params.lang + '/article/' + self.$route.params.id + ".json", config) .then(function(response){ self.article = Object.assign(response.data, {'dictionary': self.$route.params.lang, results: self.search_results}) self.search_results = [] @@ -168,7 +175,7 @@ function navigate_to_query(self, word) { // Get individual articles Promise.all(unwrapped.map((article) => { - return axios.get(`${oda_dev}/${article.dictionary}/article/${article.id}.json`) + return axios.get(`${ARTICLE_ENDPOINT}${article.dictionary}/article/${article.id}.json`) })) .then((response) => { @@ -231,7 +238,7 @@ export default { return (this.waiting_for_articles || this.waiting_for_metadata) && this.$route.name != 'root' }, api_pref: function() { - return api_endpoint + '/' + this.lang + '/article/' + return ARTICLE_ENDPOINT + this.lang + '/article/' }, get_oda_api: function() { return oda_api @@ -298,11 +305,11 @@ export default { this.lang = 'bob,nob' Promise.all([ - axios.get(oda_dev + '/nob/concepts.json').then(function(response){ + axios.get(ARTICLE_ENDPOINT + 'nob/concepts.json').then(function(response){ let concepts = response.data.concepts entities.bob = concepts }), - axios.get(oda_dev + '/nob/concepts.json').then(function(response){ + axios.get(ARTICLE_ENDPOINT + 'nob/concepts.json').then(function(response){ let concepts = response.data.concepts entities.nob = concepts }) @@ -326,11 +333,11 @@ export default { } // words of the month - axios.get(oda_dev + '/bob/article/5607.json').then(function(response){ + axios.get(ARTICLE_ENDPOINT + 'bob/article/5607.json').then(function(response){ self.monthly_bm = Object.assign(response.data, {dictionary: 'bob'}) }) - axios.get(oda_dev + '/nob/article/78569.json').then(function(response){ + axios.get(ARTICLE_ENDPOINT + 'nob/article/78569.json').then(function(response){ self.monthly_nn = Object.assign(response.data, {dictionary: 'nob'}) }) }).catch(function(_){ -- GitLab