From cdbca7d262af9755f5a82d34cafdff42f9f05d09 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Sat, 30 Nov 2013 13:54:52 -0500 Subject: [PATCH] more cleanup in routes/user.js --- src/routes/plugins.js | 4 +- src/routes/user.js | 89 ++++++++++++++----------------------------- 2 files changed, 30 insertions(+), 63 deletions(-) diff --git a/src/routes/plugins.js b/src/routes/plugins.js index 844bc08d64..13c2f105b0 100644 --- a/src/routes/plugins.js +++ b/src/routes/plugins.js @@ -27,8 +27,8 @@ var nconf = require('nconf'), // Static Assets app.get('/plugins/:id/*', function(req, res) { var relPath = req.url.replace('/plugins/' + req.params.id, ''); - if (Plugins.staticDirs[req.params.id]) { - var fullPath = path.join(Plugins.staticDirs[req.params.id], relPath); + if (plugins.staticDirs[req.params.id]) { + var fullPath = path.join(plugins.staticDirs[req.params.id], relPath); fs.exists(fullPath, function(exists) { if (exists) { res.sendfile(fullPath, { diff --git a/src/routes/user.js b/src/routes/user.js index 12610cbc59..9a3364071c 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -1,84 +1,51 @@ -var user = require('./../user.js'), - posts = require('./../posts.js'), - postTools = require('../postTools'), - fs = require('fs'), - utils = require('./../../public/src/utils.js'), +var fs = require('fs'), path = require('path'), winston = require('winston'), nconf = require('nconf'), - meta = require('./../meta'), async= require('async'), + + user = require('./../user'), + posts = require('./../posts'), + postTools = require('../postTools'), + utils = require('./../../public/src/utils'), + meta = require('./../meta'), RDB = require('./../redis'), - websockets = require('./../websockets.js'); + websockets = require('./../websockets'); (function (User) { User.createRoutes = function (app) { app.namespace('/users', function () { - app.get('', function (req, res) { - app.build_header({ - req: req, - res: res - }, function (err, header) { - res.send(header + app.create_route("users", "users") + templates['footer']); - }); - }); - - app.get('/latest', function (req, res) { - app.build_header({ - req: req, - res: res - }, function (err, header) { - res.send(header + app.create_route("users/latest", "users") + templates['footer']); - }); - }); - - app.get('/sort-posts', function (req, res) { - app.build_header({ - req: req, - res: res - }, function (err, header) { - res.send(header + app.create_route("users/sort-posts", "users") + templates['footer']); - }); - }); - - app.get('/sort-reputation', function (req, res) { - app.build_header({ - req: req, - res: res - }, function (err, header) { - res.send(header + app.create_route("users/sort-reputation", "users") + templates['footer']); - }); - }); + var routes = ['', '/latest', '/sort-posts', '/sort-reputation', '/online', '/search']; - app.get('/online', function (req, res) { - app.build_header({ - req: req, - res: res - }, function (err, header) { - res.send(header + app.create_route("users/online", "users") + templates['footer']); + function createRoute(routeName) { + app.get(routeName, function (req, res) { + app.build_header({ + req: req, + res: res + }, function (err, header) { + res.send(header + app.create_route("users" + routeName, "users") + templates['footer']); + }); }); - }); + } - app.get('/search', function (req, res) { - app.build_header({ - req: req, - res: res - }, function (err, header) { - res.send(header + app.create_route("users/search", "users") + templates['footer']); - }); - }); + for (var i=0; i