diff --git a/lib/factory.js b/lib/factory.js index ec61410..822bf60 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -84,8 +84,17 @@ function createClient(options) { // Try to load the provider from providers folder handler = require('./providers/' + provider); } catch (err) { - // Fall back to pkgcloud - handler = require('pkgcloud').storage; + try { + // Fall back to using an external provider + handler = require(provider); + if (!handler || !handler.createClient) { + // Fall back to pkgcloud + handler = require('pkgcloud').storage; + } + } catch(err) { + // Fall back to pkgcloud + handler = require('pkgcloud').storage; + } } patchContainerAndFileClass(provider); return handler.createClient(options); @@ -101,8 +110,13 @@ function getProvider(provider) { // Try to load the provider from providers folder return require('./providers/' + provider); } catch (err) { - // Fall back to pkgcloud - return require('pkgcloud').providers[provider]; + try { + // Fall back to using an external provider + return require(provider); + } catch(err) { + // Fall back to pkgcloud + return require('pkgcloud').providers[provider]; + } } }