From 3d4a8ecf6d45777fe25c7c76324514d3a5e763e9 Mon Sep 17 00:00:00 2001 From: aterox Date: Sun, 6 Mar 2022 03:06:05 -0500 Subject: [PATCH] Replace static conf.yml import --- src/utils/InitServiceWorker.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utils/InitServiceWorker.js b/src/utils/InitServiceWorker.js index 7c854288..b2956571 100644 --- a/src/utils/InitServiceWorker.js +++ b/src/utils/InitServiceWorker.js @@ -1,7 +1,8 @@ +import axios from 'axios'; +import yaml from 'js-yaml'; import { register } from 'register-service-worker'; import { sessionStorageKeys } from '@/utils/defaults'; import { statusMsg, statusErrorMsg } from '@/utils/CoolConsole'; -import conf from '../../public/conf.yml'; /* Sets a local storage item with the state from the SW lifecycle */ const setSwStatus = (swStateToSet) => { @@ -31,7 +32,8 @@ const setSwStatus = (swStateToSet) => { * Disable if not running in production * Or disable if user specified to disable */ -const shouldEnableServiceWorker = () => { +const shouldEnableServiceWorker = async () => { + const conf = yaml.load((await axios.get('conf.yml')).data); if (conf && conf.appConfig && conf.appConfig.enableServiceWorker) { setSwStatus({ disabledByUser: false }); return true; @@ -51,8 +53,8 @@ const printSwStatus = (msg) => { const swUrl = `${process.env.BASE_URL || '/'}service-worker.js`; /* If service worker enabled, then register it, and print message when status changes */ -const registerServiceWorker = () => { - if (shouldEnableServiceWorker()) { +const registerServiceWorker = async () => { + if (await shouldEnableServiceWorker()) { register(swUrl, { ready() { setSwStatus({ ready: true });