diff --git a/lib/cartodb/server.js b/lib/cartodb/server.js index 6cad6466..225b61c4 100644 --- a/lib/cartodb/server.js +++ b/lib/cartodb/server.js @@ -80,22 +80,7 @@ module.exports = function(serverOptions) { max_user_templates: global.environment.maxUserTemplates }); - var surrogateKeysCacheBackends = []; - - if (serverOptions.varnish_purge_enabled) { - surrogateKeysCacheBackends.push( - new VarnishHttpCacheBackend(serverOptions.varnish_host, serverOptions.varnish_http_port) - ); - } - - if (serverOptions.fastly && - !!serverOptions.fastly.enabled && !!serverOptions.fastly.apiKey && !!serverOptions.fastly.serviceId) { - surrogateKeysCacheBackends.push( - new FastlyCacheBackend(serverOptions.fastly.apiKey, serverOptions.fastly.serviceId) - ); - } - - var surrogateKeysCache = new SurrogateKeysCache(surrogateKeysCacheBackends); + var surrogateKeysCache = new SurrogateKeysCache(surrogateKeysCacheBackends(serverOptions)); function invalidateNamedMap (owner, templateName) { var startTime = Date.now(); @@ -440,6 +425,7 @@ module.exports = function(serverOptions) { } ); }; + // jshint maxcomplexity:6 return app; }; @@ -515,6 +501,25 @@ function setupLogger(app, opts) { } } +function surrogateKeysCacheBackends(serverOptions) { + var cacheBackends = []; + + if (serverOptions.varnish_purge_enabled) { + cacheBackends.push( + new VarnishHttpCacheBackend(serverOptions.varnish_host, serverOptions.varnish_http_port) + ); + } + + if (serverOptions.fastly && + !!serverOptions.fastly.enabled && !!serverOptions.fastly.apiKey && !!serverOptions.fastly.serviceId) { + cacheBackends.push( + new FastlyCacheBackend(serverOptions.fastly.apiKey, serverOptions.fastly.serviceId) + ); + } + + return cacheBackends; +} + function statusFromErrorMessage(errMsg) { // Find an appropriate statusCode based on message var statusCode = 400;