diff --git a/src/routes/api.js b/src/routes/api.js index d7b0efb6db..0bd255c5e0 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -13,9 +13,7 @@ var path = require('path'), meta = require('./../meta'), plugins = require('./../plugins'), utils = require('./../../public/src/utils'), - pkg = require('./../../package.json'), - - customTemplates = []; + pkg = require('./../../package.json'); function searchTerm(req, res, next) { @@ -137,7 +135,7 @@ function getModerators(req, res, next) { function getTemplatesListing(req, res, next) { utils.walk(nconf.get('views_dir'), function (err, data) { - data = data.concat(customTemplates) + data = data.concat(require('./plugins').getCustomTemplates()) .filter(function(value, index, self) { return self.indexOf(value) === index; }).map(function(el) { @@ -152,8 +150,6 @@ module.exports = function(app, middleware, controllers) { app.namespace('/api', function () { app.all('*', middleware.updateLastOnlineTime, middleware.prepareAPI); - customTemplates = app.get_custom_templates(); - app.get('/config', controllers.api.getConfig); app.get('/user/uid/:uid', middleware.checkGlobalPrivacySettings, controllers.accounts.getUserByUID); diff --git a/src/routes/plugins.js b/src/routes/plugins.js index 7fadbebd98..b4841261f4 100644 --- a/src/routes/plugins.js +++ b/src/routes/plugins.js @@ -7,7 +7,9 @@ var _ = require('underscore'), validator = require('validator'), async = require('async'), - plugins = require('../plugins'); + plugins = require('../plugins'), + + pluginRoutes = []; function setupPluginRoutes(app) { var custom_routes = { @@ -16,12 +18,6 @@ function setupPluginRoutes(app) { 'templates': [] }; - app.get_custom_templates = function() { - return custom_routes.templates.map(function(tpl) { - return tpl.template; - }); - }; - plugins.ready(function() { /* * TO BE DEPRECATED post 0.4x and replaced with something that isn't as complicated as this... @@ -30,6 +26,8 @@ function setupPluginRoutes(app) { var route, routes = custom_routes.routes; + pluginRoutes = custom_routes; + for (route in routes) { if (routes.hasOwnProperty(route)) { (function(route) { @@ -70,7 +68,6 @@ function setupPluginRoutes(app) { }(route)); } } - }); }); } @@ -186,4 +183,12 @@ module.exports = function(app, middleware, controllers) { setupPluginRoutes(app); setupPluginAdminRoutes(app); + + return { + getCustomTemplates: function() { + pluginRoutes.templates.map(function(tpl) { + return tpl.template; + }); + } + }; }; \ No newline at end of file