Node.js based forum software built for the modern web
first pass at subfolder
Baris Usakli6eb9af77e605
diff --git a/app.js b/app.jsindex d74b7cf513..96ea6fee76 100644--- a/app.js+++ b/app.js@@ -2,6 +2,7 @@var fs = require('fs'),path = require('path'),utils = require('./public/src/utils.js'),+ url = require('url'),args = {};// Runtime environment@@ -21,6 +22,8 @@ fs.readFile(path.join(__dirname, 'config.json'), function(err, data) {global.config = JSON.parse(data);global.config.url = global.config.base_url + (global.config.use_port ? ':' + global.config.port : '') + '/';global.config.upload_url = global.config.url + 'uploads/';++console.log('Info: Base Configuration OK.');var meta = require('./src/meta.js');@@ -71,11 +74,13 @@ fs.readFile(path.join(__dirname, 'config.json'), function(err, data) {default_categories = JSON.parse(default_categories);for (var category in default_categories) {+ console.log(category);admin.categories.create(default_categories[category]);}});- // Hardcoding uid 1 as an admin++ console.log('Info: Hardcoding uid 1 as an admin');var user = require('./src/user.js');user.makeAdministrator(1);} else {@@ -123,11 +128,17 @@ fs.readFile(path.join(__dirname, 'config.json'), function(err, data) {if (!secret) secret = utils.generateUUID();if (!bcrypt_rounds) bcrypt_rounds = 10;+ var urlObject = url.parse(base_url);+ var relative_path = urlObject.pathname;+ var host = urlObject.host;+ var protocol = urlObject.protocol;+var fs = require('fs'),path = require('path'),config = {secret: secret,base_url: base_url,+ relative_path: relative_path,port: port,use_port: use_port,upload_path: '/public/uploads/',@@ -162,10 +173,11 @@ fs.readFile(path.join(__dirname, 'config.json'), function(err, data) {// Client-side configfs.writeFile(path.join(__dirname, 'public', 'config.json'), JSON.stringify({socket: {- address: base_url,+ address: protocol + '//' + host,port: port},- api_url: base_url + (use_port ? ':' + port : '') + '/api/'+ api_url: protocol + '//' + host + (use_port ? ':' + port : '') + relative_path + '/api/',+ relative_path: relative_path}, null, 4));});});diff --git a/package.json b/package.jsonindex 6ec3aa08cb..3ea57dc4a3 100644--- a/package.json+++ b/package.json@@ -36,6 +36,7 @@"socket.io": "0.9.14","redis": "0.8.3","express": "3.2.0",+ "express-namespace": "0.1.1","connect": "2.7.6","emailjs": "0.3.4","cookie": "0.0.6",diff --git a/public/src/ajaxify.js b/public/src/ajaxify.jsindex 060373230f..d86225070e 100644--- a/public/src/ajaxify.js+++ b/public/src/ajaxify.js@@ -38,12 +38,12 @@ var ajaxify = {};} else if (templates[url]) {tpl_url = url;}-+if (templates.is_available(tpl_url) && !templates.force_refresh(tpl_url)) {if (quiet !== true) {window.history.pushState({"url": url- }, url, "/" + url);+ }, url, RELATIVE_PATH + '/' + url);}jQuery('#footer, #content').fadeOut(100);diff --git a/public/src/app.js b/public/src/app.jsindex d032a303b4..7007784a12 100644--- a/public/src/app.js+++ b/public/src/app.js@@ -1,15 +1,17 @@var socket,config,app = {},- API_URL = null;+ API_URL = null,+ RELATIVE_PATH = null;// todo: cleanup,etc(function() {$.ajax({- url: '/config.json?v=' + new Date().getTime(),+ url: '/forum/config.json?v=' + new Date().getTime(),success: function(data) {API_URL = data.api_url;+ RELATIVE_PATH = data.relative_path;config = data;socket = io.connect(config.socket.address + (config.socket.port ? ':' + config.socket.port : ''));@@ -244,6 +246,7 @@ var socket,}}, false);+ $.getScript(RELATIVE_PATH + '/src/forum/footer.js');addTouchEvents();});diff --git a/public/src/templates.js b/public/src/templates.jsindex 871ce28242..07080492a6 100644--- a/public/src/templates.js+++ b/public/src/templates.js@@ -86,9 +86,12 @@}function loadClient() {- jQuery.when(jQuery.getJSON('/templates/config.json'), jQuery.getJSON('/api/get_templates_listing')).done(function(config_data, templates_data) {+ jQuery.when(jQuery.getJSON(RELATIVE_PATH + '/templates/config.json'), jQuery.getJSON(RELATIVE_PATH + '/api/get_templates_listing')).done(function(config_data, templates_data) {config = config_data[0];available_templates = templates_data[0];+++templates.ready();});}@@ -131,7 +134,7 @@var timestamp = new Date().getTime(); //debugif (!templates[tpl_url]) {- jQuery.get('/templates/' + tpl_url + '.tpl?v=' + timestamp, function(html) {+ jQuery.get(RELATIVE_PATH + '/templates/' + tpl_url + '.tpl?v=' + timestamp, function(html) {var template = function() {this.toString = function() {return this.html;@@ -153,7 +156,10 @@}());(function() {+ console.log(API_URL,api_url);jQuery.get(API_URL + api_url, function(data) {++if(!data) {ajaxify.go('404');return;@@ -170,6 +176,7 @@function parse_template() {if (!templates[tpl_url] || !template_data) return;+ template_data['relative_path'] = RELATIVE_PATH || global.config.relative_path;document.getElementById('content').innerHTML = templates[tpl_url].parse(template_data);diff --git a/public/templates/account.tpl b/public/templates/account.tplindex cc4e04a9bc..da49e47d71 100644--- a/public/templates/account.tpl+++ b/public/templates/account.tpl@@ -101,4 +101,4 @@<input type="hidden" template-variable="theirid" value="{theirid}" /><input type="hidden" template-type="boolean" template-variable="isFollowing" value="{isFollowing}" />-<script type="text/javascript" src="/src/forum/account.js"></script>\ No newline at end of file+<script type="text/javascript" src="{relative_path}/src/forum/account.js"></script>\ No newline at end of filediff --git a/public/templates/accountedit.tpl b/public/templates/accountedit.tplindex e96b9b6d44..b58d0ab5ec 100644--- a/public/templates/accountedit.tpl+++ b/public/templates/accountedit.tpl@@ -170,4 +170,4 @@<input type="hidden" template-variable="gravatarpicture" value="{gravatarpicture}" /><input type="hidden" template-variable="uploadedpicture" value="{uploadedpicture}" />-<script type="text/javascript" src="/src/forum/accountedit.js"></script>\ No newline at end of file+<script type="text/javascript" src="{relative_path}/src/forum/accountedit.js"></script>\ No newline at end of filediff --git a/public/templates/category.tpl b/public/templates/category.tplindex baa73ad197..3b192e00c2 100644--- a/public/templates/category.tpl+++ b/public/templates/category.tpl@@ -73,7 +73,7 @@</div><div class="block-content"><!-- BEGIN active_users -->- <a href="/users/{active_users.userslug}"><img title="{active_users.username}" src="/graph/users/{active_users.username}/picture" class="img-polaroid" /></a>+ <a href="/users/{active_users.userslug}"><img title="{active_users.username}" src="../../graph/users/{active_users.username}/picture" class="img-polaroid" /></a><!-- END active_users --></div></div>@@ -83,7 +83,7 @@</div><div class="block-content"><!-- BEGIN moderators -->- <a href="/users/{moderators.userslug}"><img title="{moderators.username}" src="/graph/users/{moderators.username}/picture" class="img-polaroid" /></a>+ <a href="/users/{moderators.userslug}"><img title="{moderators.username}" src="../../graph/users/{active_users.username}/picture" class="img-polaroid" /></a><!-- END moderators --></div></div>@@ -94,4 +94,5 @@<input type="hidden" template-variable="twitter-intent-url" value="{twitter-intent-url}" /><input type="hidden" template-variable="facebook-share-url" value="{facebook-share-url}" /><input type="hidden" template-variable="google-share-url" value="{google-share-url}" />-<script type="text/javascript" src="/src/forum/category.js"></script>\ No newline at end of file++<script type="text/javascript" src="{relative_path}/src/forum/category.js"></script>\ No newline at end of filediff --git a/public/templates/followers.tpl b/public/templates/followers.tplindex 139a14dd56..45d973e898 100644--- a/public/templates/followers.tpl+++ b/public/templates/followers.tpl@@ -41,4 +41,4 @@<input type="hidden" template-variable="theirid" value="{theirid}" /><input type="hidden" template-variable="followersCount" value="{followersCount}" />-<script type="text/javascript" src="/src/forum/followers.js"></script>\ No newline at end of file+<script type="text/javascript" src="{relative_path}/src/forum/followers.js"></script>\ No newline at end of filediff --git a/public/templates/following.tpl b/public/templates/following.tplindex a167182c8c..38b84c45d4 100644--- a/public/templates/following.tpl+++ b/public/templates/following.tpl@@ -45,4 +45,4 @@<input type="hidden" template-variable="theirid" value="{theirid}" /><input type="hidden" template-variable="followingCount" value="{followingCount}" />-<script type="text/javascript" src="/src/forum/following.js"></script>+<script type="text/javascript" src="{relative_path}/src/forum/following.js"></script>diff --git a/public/templates/footer.tpl b/public/templates/footer.tplindex d9c02f0d34..51d3b71df6 100644--- a/public/templates/footer.tpl+++ b/public/templates/footer.tpl@@ -45,7 +45,6 @@<button id="mobile-menu-btn" type="button" class="btn btn-none"><i class="icon-th icon-2x"></i></button><button id="mobile-post-btn" type="button" class="btn btn-none"><i class="icon-plus icon-2x"></i></button></div>- <script type="text/javascript" src="/src/forum/footer.js"></script><!-- END Forum Info --></body>diff --git a/public/templates/header.tpl b/public/templates/header.tplindex 667597b747..6cc5d0a350 100644--- a/public/templates/header.tpl+++ b/public/templates/header.tpl@@ -9,27 +9,27 @@<meta http-equiv="content-type" content="text/html; charset=UTF-8" /><meta name="apple-mobile-web-app-capable" content="yes" /><link href="{cssSrc}" rel="stylesheet" media="screen">- <link href="/vendor/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">- <link rel="stylesheet" href="/vendor/fontawesome/css/font-awesome.min.css">+ <link href="{relative_path}/vendor/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">+ <link rel="stylesheet" href="{relative_path}/vendor/fontawesome/css/font-awesome.min.css"><script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>- <script type="text/javascript" src="/vendor/jquery/js/jquery-ui-1.10.3.custom.min.js"></script>- <script type="text/javascript" src="/vendor/bootstrap/js/bootstrap.min.js"></script>- <script type="text/javascript" src="/socket.io/socket.io.js"></script>- <script type="text/javascript" src="/src/app.js"></script>- <script src="/vendor/requirejs/require.js"></script>- <script src="/vendor/bootbox/bootbox.min.js"></script>+ <script type="text/javascript" src="{relative_path}/vendor/jquery/js/jquery-ui-1.10.3.custom.min.js"></script>+ <script type="text/javascript" src="{relative_path}/vendor/bootstrap/js/bootstrap.min.js"></script>+ <script type="text/javascript" src="{relative_path}/socket.io/socket.io.js"></script>+ <script type="text/javascript" src="{relative_path}/src/app.js"></script>+ <script src="{relative_path}/vendor/requirejs/require.js"></script>+ <script src="{relative_path}/vendor/bootbox/bootbox.min.js"></script><script>require.config({- baseUrl: "/src/modules",+ baseUrl: "{relative_path}/src/modules",waitSeconds: 3});</script>- <script type="text/javascript" src="/src/templates.js"></script>- <script type="text/javascript" src="/src/ajaxify.js"></script>- <script type="text/javascript" src="/src/jquery.form.js"></script>- <script type="text/javascript" src="/src/utils.js"></script>+ <script type="text/javascript" src="{relative_path}/src/templates.js"></script>+ <script type="text/javascript" src="{relative_path}/src/ajaxify.js"></script>+ <script type="text/javascript" src="{relative_path}/src/jquery.form.js"></script>+ <script type="text/javascript" src="{relative_path}/src/utils.js"></script>- <link rel="stylesheet" type="text/css" href="/css/nodebb.css" />+ <link rel="stylesheet" type="text/css" href="{relative_path}/css/nodebb.css" /></head><body>diff --git a/public/templates/login.tpl b/public/templates/login.tplindex 4cf156f7a6..a3847fbb71 100644--- a/public/templates/login.tpl+++ b/public/templates/login.tpl@@ -27,4 +27,4 @@</div></div>-<script type="text/javascript" src="/src/forum/login.js"></script>\ No newline at end of file+<script type="text/javascript" src="{relative_path}/src/forum/login.js"></script>\ No newline at end of filediff --git a/public/templates/recent.tpl b/public/templates/recent.tplindex 1c8fbf8af9..aa4bb57255 100644--- a/public/templates/recent.tpl+++ b/public/templates/recent.tpl@@ -26,8 +26,8 @@<div class="row-fluid"><div class="span12 topic-row img-polaroid"><div class="latest-post visible-desktop">- <div class="pull-right">- <img style="width: 48px; height: 48px; /*temporary*/" src="../../graph/users/{topics.teaser_username}/picture" />+ <div class="pull-right">+ <img style="width: 48px; height: 48px; /*temporary*/" src="graph/users/{topics.teaser_username}/picture" /><p><strong>{topics.teaser_username}</strong>: {topics.teaser_text}</p><span>posted {topics.teaser_timestamp} ago</span></div>@@ -49,4 +49,4 @@</div></div>-<script type="text/javascript" src="/src/forum/recent.js"></script>\ No newline at end of file+<script type="text/javascript" src="{relative_path}/src/forum/recent.js"></script>\ No newline at end of filediff --git a/public/templates/register.tpl b/public/templates/register.tplindex 5a2cea9fc5..7b149091ef 100644--- a/public/templates/register.tpl+++ b/public/templates/register.tpl@@ -20,4 +20,4 @@</div></div>-<script type="text/javascript" src="/src/forum/register.js"></script>\ No newline at end of file+<script type="text/javascript" src="{relative_path}/src/forum/register.js"></script>\ No newline at end of filediff --git a/public/templates/reset.tpl b/public/templates/reset.tplindex 3a1857a4f4..42d3d12f08 100644--- a/public/templates/reset.tpl+++ b/public/templates/reset.tpl@@ -14,4 +14,4 @@<button class="btn btn-primary" id="reset" type="submit">Reset Password</button></div>-<script type="text/javascript" src="/src/forum/reset.js"></script>\ No newline at end of file+<script type="text/javascript" src="{relative_path}/src/forum/reset.js"></script>\ No newline at end of filediff --git a/public/templates/reset_code.tpl b/public/templates/reset_code.tplindex a37d4534df..700005b3f7 100644--- a/public/templates/reset_code.tpl+++ b/public/templates/reset_code.tpl@@ -22,4 +22,4 @@<input type="hidden" template-variable="reset_code" value="{reset_code}" />-<script type="text/javascript" src="/src/forum/reset_code.js"></script>\ No newline at end of file+<script type="text/javascript" src="{relative_path}/src/forum/reset_code.js"></script>\ No newline at end of filediff --git a/public/templates/topic.tpl b/public/templates/topic.tplindex 9d716a1e3d..576afb828f 100644--- a/public/templates/topic.tpl+++ b/public/templates/topic.tpl@@ -140,4 +140,4 @@-<script type="text/javascript" src="/src/forum/topic.js"></script>\ No newline at end of file+<script type="text/javascript" src="{relative_path}/src/forum/topic.js"></script>\ No newline at end of filediff --git a/public/templates/users.tpl b/public/templates/users.tplindex 8f6da1c8b2..3904e6db06 100644--- a/public/templates/users.tpl+++ b/public/templates/users.tpl@@ -36,4 +36,4 @@</ul></div>-<script type="text/javascript" src="/src/forum/users.js"></script>\ No newline at end of file+<script type="text/javascript" src="{relative_path}/src/forum/users.js"></script>\ No newline at end of filediff --git a/src/categories.js b/src/categories.jsindex df390e4055..1d2575bfe1 100644--- a/src/categories.js+++ b/src/categories.js@@ -309,7 +309,7 @@ var RDB = require('./redis.js'),}Categories.getCategories = function(cids, callback, current_user) {- if (cids.length === 0) {+ if (!cids || cids.length === 0) {callback({'categories' : []});return;}diff --git a/src/user.js b/src/user.jsindex 0c2ab2f73c..a80a10c873 100644--- a/src/user.js+++ b/src/user.js@@ -14,10 +14,9 @@ var utils = require('./../public/src/utils.js'),User.create = function(username, password, email, callback) {username = username.trim(), email = email.trim();- // @todo return a proper error? use node-validator?+ // @todo use node-validator?if(!utils.isEmailValid(email) || !utils.isUserNameValid(username) || !utils.isPasswordValid(password)) {- console.log('Invalid email/username/password!');- callback(null, 0);+ callback('Invalid email/username/password!', 0);return;}@@ -25,13 +24,13 @@ var utils = require('./../public/src/utils.js'),User.exists(userslug, function(exists) {if(exists) {- callback(null, 0);+ callback('Username taken!', 0);return;}User.isEmailAvailable(email, function(available) {if(!available) {- callback(null, 0);+ callback('Email taken!', 0);return;}diff --git a/src/webserver.js b/src/webserver.jsindex 4c5d7ee007..d3a8b79224 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -1,4 +1,5 @@var express = require('express'),+ express_namespace = require('express-namespace'),WebServer = express(),server = require('http').createServer(WebServer),RedisStore = require('connect-redis')(express),@@ -26,16 +27,18 @@ var express = require('express'),app.build_header = function(res) {return templates['header'].parse({- cssSrc: global.config['theme:src'] || '/vendor/bootstrap/css/bootstrap.min.css',+ cssSrc: global.config['theme:src'] || global.config.relative_path + '/vendor/bootstrap/css/bootstrap.min.css',title: global.config['title'] || 'NodeBB',- csrf:res.locals.csrf_token+ csrf:res.locals.csrf_token,+ relative_path: global.config.relative_path});};// Middlewaresapp.use(express.favicon(path.join(__dirname, '../', 'public', 'favicon.ico')));app.use(require('less-middleware')({ src: path.join(__dirname, '../', 'public') }));- app.use(express.static(path.join(__dirname, '../', 'public')));+ //app.use(express.static(path.join(__dirname, '../', 'public')));+ app.use(global.config.relative_path, express.static(path.join(__dirname, '../', 'public')));app.use(express.bodyParser()); // Puts POST vars in request.bodyapp.use(express.cookieParser()); // If you want to parse cookies (res.cookies)app.use(express.compress());@@ -108,11 +111,7 @@ var express = require('express'),res.json('500', { error: err.message });});- auth.create_routes(app);- admin.create_routes(app);- userRoute.create_routes(app);- installRoute.create_routes(app);- testBed.create_routes(app);+app.create_route = function(url, tpl) { // to removereturn '<script>templates.ready(function(){ajaxify.go("' + url + '", null, "' + tpl + '");});</script>';@@ -141,77 +140,156 @@ var express = require('express'),}());// Complex Routes- app.get('/', function(req, res) {- categories.getAllCategories(function(returnData) {- res.send(- app.build_header(res) +- '\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/home'].parse(returnData) + '\n\t</noscript>' +- app.create_route('') +- templates['footer']- );- }, 0);- });+ app.namespace(global.config.relative_path, function() {++ auth.create_routes(app);+ admin.create_routes(app);+ userRoute.create_routes(app);+ installRoute.create_routes(app);+ testBed.create_routes(app);++ app.get('/', function(req, res) {+ console.log('going in home');+ categories.getAllCategories(function(returnData) {+ res.send(+ app.build_header(res) ++ '\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/home'].parse(returnData) + '\n\t</noscript>' ++ app.create_route('') ++ templates['footer']+ );+ }, 0);+ });+++ app.get('/topic/:topic_id/:slug?', function(req, res) {+ var tid = req.params.topic_id;+ if (tid.match('.rss')) {+ fs.readFile('feeds/topics/' + tid, function (err, data) {+ if (err) {+ res.type('text').send(404, "Unable to locate an rss feed at this location.");+ return;+ }++ res.type('xml').set('Content-Length', data.length).send(data);+ });+ return;+ }- app.get('/topic/:topic_id/:slug?', function(req, res) {- var tid = req.params.topic_id;- if (tid.match('.rss')) {- fs.readFile('feeds/topics/' + tid, function (err, data) {- if (err) {- res.type('text').send(404, "Unable to locate an rss feed at this location.");++ var topic_url = tid + (req.params.slug ? '/' + req.params.slug : '');+ topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), function(err, topic) {+ if (err) return res.redirect('404');++ res.send(+ app.build_header(res) ++ '\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/topic'].parse(topic) + '\n\t</noscript>' ++ '\n\t<script>templates.ready(function(){ajaxify.go("topic/' + topic_url + '");});</script>' ++ templates['footer']+ );+ });+ });++ app.get('/category/:category_id/:slug?', function(req, res) {+ var cid = req.params.category_id;+ if (cid.match('.rss')) {+ fs.readFile('feeds/categories/' + cid, function (err, data) {+ if (err) {+ res.type('text').send(404, "Unable to locate an rss feed at this location.");+ return;+ }++ res.type('xml').set('Content-Length', data.length).send(data);+ });+ return;+ }++ var category_url = cid + (req.params.slug ? '/' + req.params.slug : '');+ categories.getCategoryById(cid, 0, function(returnData) {+ if(!returnData) {+ res.redirect('404');return;}- res.type('xml').set('Content-Length', data.length).send(data);+ res.send(+ app.build_header(res) ++ '\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/category'].parse(returnData) + '\n\t</noscript>' ++ '\n\t<script>templates.ready(function(){ajaxify.go("category/' + category_url + '");});</script>' ++ templates['footer']+ );});- return;- }+ });+ app.get('/confirm/:code', function(req, res) {+ res.send(app.build_header(res) + '<script>templates.ready(function(){ajaxify.go("confirm/' + req.params.code + '");});</script>' + templates['footer']);+ });- var topic_url = tid + (req.params.slug ? '/' + req.params.slug : '');- topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), function(err, topic) {- if (err) return res.redirect('404');+ app.get('/api/:method', api_method);+ app.get('/api/:method/:id', api_method);+ // ok fine MUST ADD RECURSION style. I'll look for a better fix in future but unblocking baris for this:+ app.get('/api/:method/:id/:section?', api_method);+ app.get('/api/:method/:id*', api_method);++ app.get('/cid/:cid', function(req, res) {+ categories.getCategoryData(req.params.cid, function(data){+ if(data)+ res.send(data);+ else+ res.send(404, "Category doesn't exist!");+ });+ });- res.send(- app.build_header(res) +- '\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/topic'].parse(topic) + '\n\t</noscript>' +- '\n\t<script>templates.ready(function(){ajaxify.go("topic/' + topic_url + '");});</script>' +- templates['footer']- );+ app.get('/tid/:tid', function(req, res) {+ topics.getTopicData(req.params.tid, function(data){+ if(data)+ res.send(data);+ else+ res.send(404, "Topic doesn't exist!");+ });});- });- app.get('/category/:category_id/:slug?', function(req, res) {- var cid = req.params.category_id;- if (cid.match('.rss')) {- fs.readFile('feeds/categories/' + cid, function (err, data) {- if (err) {- res.type('text').send(404, "Unable to locate an rss feed at this location.");+ app.get('/pid/:pid', function(req, res) {+ posts.getPostData(req.params.pid, function(data){+ if(data)+ res.send(data);+ else+ res.send(404, "Post doesn't exist!");+ });+ });+++ //START TODO: MOVE TO GRAPH.JS++ app.get('/graph/users/:username/picture', function(req, res) {+ user.get_uid_by_username(req.params.username, function(uid) {+ if (uid == null) {+ res.json({+ status: 0+ });return;}-- res.type('xml').set('Content-Length', data.length).send(data);+ user.getUserField(uid, 'picture', function(picture) {+ if (picture == null) res.redirect('http://www.gravatar.com/avatar/a938b82215dfc96c4cabeb6906e5f953&default=identicon');+ res.redirect(picture);+ });});- return;- }++ });- var category_url = cid + (req.params.slug ? '/' + req.params.slug : '');- categories.getCategoryById(cid, 0, function(returnData) {- if(!returnData) {- res.redirect('404');- return;- }+ //END TODO: MOVE TO GRAPH.JS++ app.get('/test', function(req, res) {++ console.log('derp');+ user.get_userslugs_by_uids([1,2], function(data) {+ res.send(data);+ });++ /* categories.getCategoryById(1,1, function(data) {+ res.send(data);+ },1);*/- res.send(- app.build_header(res) +- '\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/category'].parse(returnData) + '\n\t</noscript>' +- '\n\t<script>templates.ready(function(){ajaxify.go("category/' + category_url + '");});</script>' +- templates['footer']- );});- });- app.get('/confirm/:code', function(req, res) {- res.send(app.build_header(res) + '<script>templates.ready(function(){ajaxify.go("confirm/' + req.params.code + '");});</script>' + templates['footer']);});// These functions are called via ajax once the initial page is loaded to populate templates with data@@ -342,73 +420,10 @@ var express = require('express'),}}- app.get('/api/:method', api_method);- app.get('/api/:method/:id', api_method);- // ok fine MUST ADD RECURSION style. I'll look for a better fix in future but unblocking baris for this:- app.get('/api/:method/:id/:section?', api_method);- app.get('/api/:method/:id*', api_method);-- app.get('/cid/:cid', function(req, res) {- categories.getCategoryData(req.params.cid, function(data){- if(data)- res.send(data);- else- res.send(404, "Category doesn't exist!");- });- });-- app.get('/tid/:tid', function(req, res) {- topics.getTopicData(req.params.tid, function(data){- if(data)- res.send(data);- else- res.send(404, "Topic doesn't exist!");- });- });-- app.get('/pid/:pid', function(req, res) {- posts.getPostData(req.params.pid, function(data){- if(data)- res.send(data);- else- res.send(404, "Post doesn't exist!");- });- });--- app.get('/test', function(req, res) {-- console.log('derp');- user.get_userslugs_by_uids([1,2], function(data) {- res.send(data);- });--/* categories.getCategoryById(1,1, function(data) {- res.send(data);- },1);*/-- });--- //START TODO: MOVE TO GRAPH.JS+- app.get('/graph/users/:username/picture', function(req, res) {- user.get_uid_by_username(req.params.username, function(uid) {- if (uid == null) {- res.json({- status: 0- });- return;- }- user.getUserField(uid, 'picture', function(picture) {- if (picture == null) res.redirect('http://www.gravatar.com/avatar/a938b82215dfc96c4cabeb6906e5f953&default=identicon');- res.redirect(picture);- });- });-- });- //END TODO: MOVE TO GRAPH.JS+}(WebServer));server.listen(config.port);