var user = require('./../user.js'), auth = require('./authentication.js'), topics = require('./../topics.js'), categories = require('./../categories.js') utils = require('./../../public/src/utils.js'), pkg = require('../../package.json'), meta = require('./../meta.js'); (function(Api) { Api.create_routes = function(app) { app.get('/api/get_templates_listing', function(req, res) { utils.walk(global.configuration.ROOT_DIRECTORY + '/public/templates', function(err, data) { res.json(data); }); }); app.get('/api/config', function(req, res, next) { var config = require('../../public/config.json'); config['postDelay'] = meta.config['postDelay']; config['minimumTitleLength'] = meta.config['minimumTitleLength']; config['minimumPostLength'] = meta.config['minimumPostLength']; config['imgurClientIDSet'] = !!meta.config['imgurClientID']; res.json(200, config); }); app.get('/api/home', function(req, res) { var uid = (req.user) ? req.user.uid : 0; categories.getAllCategories(function(data) { data.categories = data.categories.filter(function(category) { return (!category.disabled || category.disabled === "0"); }); function iterator(category, callback) { categories.getRecentReplies(category.cid, 2, function(posts) { category["posts"] = posts; category["post_count"] = posts.length>2 ? 2 : posts.length; callback(null); }); } require('async').each(data.categories, iterator, function(err) { data.motd_class = (meta.config.show_motd === '1' || meta.config.show_motd === undefined) ? '' : 'none'; data.motd = marked(meta.config.motd || "# NodeBB v " + pkg.version + "\nWelcome to NodeBB, the discussion platform of the future.\n\n Get NodeBB  Fork us on Github  @dcplabs"); res.json(data); }); }, uid); }); app.get('/api/login', function(req, res) { var data = {}, login_strategies = auth.get_login_strategies(), num_strategies = login_strategies.length; if (num_strategies == 0) { data = { 'login_window:spansize': 'span12', 'alternate_logins:display': 'none' }; } else { data = { 'login_window:spansize': 'span6', 'alternate_logins:display': 'block' } for (var i=0, ii=num_strategies; i