From f3e7706506277fc35f01281cd050bc64236770b7 Mon Sep 17 00:00:00 2001 From: HenriT Date: Mon, 30 Aug 2021 20:33:49 +0300 Subject: [PATCH] No configuration setup. Wordpress compatible. --- src/config/app.config.example.js | 7 ++++++- src/config/i18n.config.js | 8 ++------ src/services/adapters/wordpress.adapter.js | 7 +++---- src/services/data.service.js | 8 +++++--- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/config/app.config.example.js b/src/config/app.config.example.js index 7acdf70..c48f9aa 100644 --- a/src/config/app.config.example.js +++ b/src/config/app.config.example.js @@ -1,3 +1,8 @@ +// const wordpress = window.name ? JSON.parse(window.name) : { front_url: '', api_url: '', nonce: '' }; + export default { - storageType: 'local' + storageType: 'local', + // locales_url: wordpress.front_url, + // api_url: wordpress.api_url, + // api_nonce: wordpress.nonce, }; diff --git a/src/config/i18n.config.js b/src/config/i18n.config.js index 13f4024..bf21571 100644 --- a/src/config/i18n.config.js +++ b/src/config/i18n.config.js @@ -4,6 +4,7 @@ import VueI18Next from '@panter/vue-i18next'; import Backend from 'i18next-http-backend'; import LanguageDetector from 'i18next-browser-languagedetector'; import app from '@/main'; +import config from '@/config/app.config'; Vue.use(VueI18Next); @@ -11,16 +12,11 @@ i18next .use(LanguageDetector) .use(Backend); -const path = window.name - ? JSON.parse(window.name).front_url - : `${window.location.origin}${process.env.BASE_URL}`; - - const initialized = i18next.init({ fallbackLng: 'en', whitelist: ['en', 'fr', 'et', 'fa', 'bn', 'es'], backend: { - loadPath: `${path}/locales/{{lng}}/{{ns}}.json`, + loadPath: config.locales_url || `${window.location.origin}${process.env.BASE_URL}/locales/{{lng}}/{{ns}}.json`, }, detection: { order: ['querystring', 'path', 'localStorage', 'navigator'], diff --git a/src/services/adapters/wordpress.adapter.js b/src/services/adapters/wordpress.adapter.js index 103e584..eb2c057 100644 --- a/src/services/adapters/wordpress.adapter.js +++ b/src/services/adapters/wordpress.adapter.js @@ -1,14 +1,13 @@ import axios from 'axios'; import app from '@/main'; +import config from '@/config/app.config'; import NotificationService from '@/services/notification.service'; import { removeVuexORMFlags } from '@/utils/helpers'; -const config = window.name ? JSON.parse(window.name) : { front_url: '', api_url: '', nonce: '' }; - const http = axios.create({ - baseURL: config.api_url, + baseURL: config.api_url || '', headers: { - 'X-WP-Nonce': config.nonce, + 'X-WP-Nonce': config.nonce || '', }, }); diff --git a/src/services/data.service.js b/src/services/data.service.js index 64bda03..5f1f486 100644 --- a/src/services/data.service.js +++ b/src/services/data.service.js @@ -7,11 +7,13 @@ class DataService { adapter = null; constructor() { - if (config.storageType === 'local') { + const type = config.storageType || 'local'; + + if (type === 'local') { this.adapter = local; - } else if (config.storageType === 'http') { + } else if (type === 'http') { this.adapter = http; - } else if (config.storageType === 'wordpress') { + } else if (type === 'wordpress') { this.adapter = wordpress; } }