Commit fd51b541 authored by Michał Woźniak's avatar Michał Woźniak
Browse files

WIP #70: config.js can now configure which plugins are loaded, and what order...

WIP #70: config.js can now configure which plugins are loaded, and what order they are going to be used in
parent 0bf6c921
......@@ -24,7 +24,16 @@ if (typeof self.SamizdatConfig !== 'object' || self.SamizdatConfig === null) {
// and move on?
defaultPluginTimeout: 10000,
// plugins settings namespace
plugins: {}
plugins: {},
// this defines which plugins get loaded,
// and the order in which they are deployed to try to retrieve content
// assumption: plugin path = ./plugins/<plugin-name>.js
strategy: [
'fetch',
'cache',
'gateway-ipns',
'gun-ipfs'
]
}
}
......@@ -33,12 +42,13 @@ if (typeof self.SamizdatConfig !== 'object' || self.SamizdatConfig === null) {
// order in which plugins are loaded defines the order
// in which they are called!
try {
// get the config
self.importScripts("./config.js")
// only now load the plugins (config.js could have changed the defaults)
self.importScripts(
"./config.js",
"./plugins/fetch.js",
"./plugins/cache.js",
"./plugins/gateway-ipns.js",
"./plugins/gun-ipfs.js");
...self.SamizdatConfig.strategy.map(
pluginName => `./plugins/${pluginName}.js`
))
} catch(e) {
// we only get a cryptic "Error while registering a service worker"
// unless we explicitly print the errors out in the console
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment