kopia lustrzana https://gitlab.com/rysiekpl/libresilient
loading config is now a separate operation than verifying its correctness (prep. for #30)
rodzic
c37cd53a89
commit
c2b62919b8
|
@ -92,11 +92,16 @@ self.log = function(component, ...items) {
|
|||
|
||||
|
||||
/**
|
||||
* verifying and loading a config JSON
|
||||
* verifying a config data object
|
||||
*
|
||||
* we are *NOT* checking for fields that are unknown/unexpected
|
||||
* as resilience is more important than conrrectness here:
|
||||
* we do want the config to load if at all it can be loaded,
|
||||
* an extra field or two is not a problem here
|
||||
*
|
||||
* cdata - config data to verify
|
||||
*/
|
||||
let loadConfigData = (cdata) => {
|
||||
let verifyConfigData = (cdata) => {
|
||||
// basic check for the plugins field
|
||||
if ( !("plugins" in cdata) || ! Array.isArray(cdata.plugins) ) {
|
||||
self.log('service-worker', 'fetched config does not contain a valid "plugins" field')
|
||||
|
@ -113,12 +118,7 @@ let loadConfigData = (cdata) => {
|
|||
self.log('service-worker', 'fetched config contains invalid "defaultPluginTimeout" data (integer expected)')
|
||||
return false;
|
||||
}
|
||||
// safe to apply defaultPluginTimeout
|
||||
self.LibResilientConfig.defaultPluginTimeout = cdata.defaultPluginTimeout
|
||||
}
|
||||
// safe to apply main config data
|
||||
self.LibResilientConfig.plugins = cdata.plugins
|
||||
self.LibResilientConfig.loggedComponents = cdata.loggedComponents
|
||||
// we're good
|
||||
return true;
|
||||
}
|
||||
|
@ -164,7 +164,10 @@ let initServiceWorker = async () => {
|
|||
} else {
|
||||
// process the data
|
||||
cdata = await cresponse.clone().json()
|
||||
if (loadConfigData(cdata)) {
|
||||
// verify the config
|
||||
if (verifyConfigData(cdata)) {
|
||||
// merge the config
|
||||
self.LibResilientConfig = {...self.LibResilientConfig, ...cdata}
|
||||
self.log('service-worker', 'config loaded.')
|
||||
// cache the valid config.json
|
||||
if (!wasCached) {
|
||||
|
|
Ładowanie…
Reference in New Issue