|
|
@ -1,4 +1,5 @@
|
|
|
|
var express = require('express'),
|
|
|
|
var express = require('express'),
|
|
|
|
|
|
|
|
express_namespace = require('express-namespace'),
|
|
|
|
WebServer = express(),
|
|
|
|
WebServer = express(),
|
|
|
|
server = require('http').createServer(WebServer),
|
|
|
|
server = require('http').createServer(WebServer),
|
|
|
|
RedisStore = require('connect-redis')(express),
|
|
|
|
RedisStore = require('connect-redis')(express),
|
|
|
@ -26,16 +27,18 @@ var express = require('express'),
|
|
|
|
|
|
|
|
|
|
|
|
app.build_header = function(res) {
|
|
|
|
app.build_header = function(res) {
|
|
|
|
return templates['header'].parse({
|
|
|
|
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',
|
|
|
|
title: global.config['title'] || 'NodeBB',
|
|
|
|
csrf:res.locals.csrf_token
|
|
|
|
csrf:res.locals.csrf_token,
|
|
|
|
|
|
|
|
relative_path: global.config.relative_path
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Middlewares
|
|
|
|
// Middlewares
|
|
|
|
app.use(express.favicon(path.join(__dirname, '../', 'public', 'favicon.ico')));
|
|
|
|
app.use(express.favicon(path.join(__dirname, '../', 'public', 'favicon.ico')));
|
|
|
|
app.use(require('less-middleware')({ src: path.join(__dirname, '../', 'public') }));
|
|
|
|
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.body
|
|
|
|
app.use(express.bodyParser()); // Puts POST vars in request.body
|
|
|
|
app.use(express.cookieParser()); // If you want to parse cookies (res.cookies)
|
|
|
|
app.use(express.cookieParser()); // If you want to parse cookies (res.cookies)
|
|
|
|
app.use(express.compress());
|
|
|
|
app.use(express.compress());
|
|
|
@ -108,11 +111,7 @@ var express = require('express'),
|
|
|
|
res.json('500', { error: err.message });
|
|
|
|
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 remove
|
|
|
|
app.create_route = function(url, tpl) { // to remove
|
|
|
|
return '<script>templates.ready(function(){ajaxify.go("' + url + '", null, "' + tpl + '");});</script>';
|
|
|
|
return '<script>templates.ready(function(){ajaxify.go("' + url + '", null, "' + tpl + '");});</script>';
|
|
|
@ -141,7 +140,16 @@ var express = require('express'),
|
|
|
|
}());
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
|
|
// Complex Routes
|
|
|
|
// Complex Routes
|
|
|
|
|
|
|
|
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) {
|
|
|
|
app.get('/', function(req, res) {
|
|
|
|
|
|
|
|
console.log('going in home');
|
|
|
|
categories.getAllCategories(function(returnData) {
|
|
|
|
categories.getAllCategories(function(returnData) {
|
|
|
|
res.send(
|
|
|
|
res.send(
|
|
|
|
app.build_header(res) +
|
|
|
|
app.build_header(res) +
|
|
|
@ -152,6 +160,7 @@ var express = require('express'),
|
|
|
|
}, 0);
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.get('/topic/:topic_id/:slug?', function(req, res) {
|
|
|
|
app.get('/topic/:topic_id/:slug?', function(req, res) {
|
|
|
|
var tid = req.params.topic_id;
|
|
|
|
var tid = req.params.topic_id;
|
|
|
|
if (tid.match('.rss')) {
|
|
|
|
if (tid.match('.rss')) {
|
|
|
@ -214,6 +223,75 @@ var express = require('express'),
|
|
|
|
res.send(app.build_header(res) + '<script>templates.ready(function(){ajaxify.go("confirm/' + req.params.code + '");});</script>' + templates['footer']);
|
|
|
|
res.send(app.build_header(res) + '<script>templates.ready(function(){ajaxify.go("confirm/' + req.params.code + '");});</script>' + templates['footer']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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!");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// These functions are called via ajax once the initial page is loaded to populate templates with data
|
|
|
|
// These functions are called via ajax once the initial page is loaded to populate templates with data
|
|
|
|
function api_method(req, res) {
|
|
|
|
function api_method(req, res) {
|
|
|
|
var uid = (req.user) ? req.user.uid : 0;
|
|
|
|
var uid = (req.user) ? req.user.uid : 0;
|
|
|
@ -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));
|
|
|
|
}(WebServer));
|
|
|
|
|
|
|
|
|
|
|
|
server.listen(config.port);
|
|
|
|
server.listen(config.port);
|
|
|
|