Node.js based forum software built for the modern web
refactored all calls to app.build_header (in regular and auth routes)
Julian Lam4588745b9a4d
diff --git a/public/templates/header.tpl b/public/templates/header.tplindex b193223431..0c7ae37264 100644--- a/public/templates/header.tpl+++ b/public/templates/header.tpl@@ -1,7 +1,7 @@<!DOCTYPE html><html><head>- <title>{title}</title>+ <title>{browserTitle}</title>{meta_tags}<link href="{cssSrc}" rel="stylesheet" media="screen"><link href="{relative_path}/vendor/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">diff --git a/src/routes/authentication.js b/src/routes/authentication.jsindex b03bce015e..19ac5345df 100644--- a/src/routes/authentication.js+++ b/src/routes/authentication.js@@ -87,7 +87,9 @@console.log('info: [Auth] Session ' + req.sessionID + ' logout (uid: ' + global.uid + ')');login_module.logout(req.sessionID, function(logout) {req.logout();- res.send(app.build_header({ req: req, res: res }) + templates['logout'] + templates['footer']);+ app.build_header({ req: req, res: res }, function(header) {+ res.send(header + templates['logout'] + templates['footer']);+ });});});@@ -121,11 +123,15 @@app.get('/reset/:code', function(req, res) {- res.send(app.build_header({ req: req, res: res }) + templates['reset_code'].parse({ reset_code: req.params.code }) + templates['footer']);+ app.build_header({ req: req, res: res }, function(header) {+ res.send(header + templates['reset_code'].parse({ reset_code: req.params.code }) + templates['footer']);+ });});app.get('/reset', function(req, res) {- res.send(app.build_header({ req: req, res: res }) + templates['reset'] + templates['footer']);+ app.build_header({ req: req, res: res }, function(header) {+ res.send(header + templates['reset'] + templates['footer']);+ });});diff --git a/src/webserver.js b/src/webserver.jsindex 9ad69d6fcf..b0c99695da 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -26,7 +26,11 @@ var express = require('express'),(function(app) {var templates = null;- app.build_header = function(options) {+ /**+ * `options` object requires: req, res+ * accepts: metaTags+ */+ app.build_header = function(options, callback) {var defaultMetaTags = [{ name: 'viewport', content: 'width=device-width, initial-scale=1.0' },{ name: 'content-type', content: 'text/html; charset=UTF-8' },@@ -41,11 +45,11 @@ var express = require('express'),meta_tags: metaString};- // meta.build_title(options.title, (options.req.user ? options.req.user.uid : 0), function(err, title) {- // if (!err) templateValues.title = title;- // });+ meta.build_title(options.title, (options.req.user ? options.req.user.uid : 0), function(err, title) {+ if (!err) templateValues.browserTitle = title;- return templates['header'].parse(templateValues);+ callback(null, templates['header'].parse(templateValues));+ });};// Middlewares@@ -159,7 +163,9 @@ var express = require('express'),return;}- res.send(app.build_header({ req: req, res: res }) + app.create_route(route) + templates['footer']);+ app.build_header({ req: req, res: res }, function(err, header) {+ res.send(header + app.create_route(route) + templates['footer']);+ });});}(routes[i]));}@@ -167,14 +173,23 @@ var express = require('express'),app.get('/', function(req, res) {- categories.getAllCategories(function(returnData) {+ async.parallel({+ "header": function(next) {+ app.build_header({ req: req, res: res }, next);+ },+ "categories": function(next) {+ categories.getAllCategories(function(returnData) {+ next(null, returnData);+ }, 0);+ }+ }, function(err, data) {res.send(- app.build_header({ req: req, res: res }) +- '\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/home'].parse(returnData) + '\n\t</noscript>' ++ data.header ++ '\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/home'].parse(data.categories) + '\n\t</noscript>' +app.create_route('') +templates['footer']);- }, 0);+ })});@@ -196,18 +211,20 @@ var express = require('express'),topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), function(err, topic) {if (err) return res.redirect('404');- res.send(- app.build_header({- req: req,- res: res,- metaTags: [- { name: "title", content: topic.topic_name }- ]- }) +- '\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.build_header({+ req: req,+ res: res,+ metaTags: [+ { name: "title", content: topic.topic_name }+ ]+ }, function(header) {+ res.send(+ header ++ '\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']+ );+ });});});@@ -230,24 +247,28 @@ var express = require('express'),categories.getCategoryById(cid, 0, function(err, returnData) {if(err) return res.redirect('404');- res.send(- app.build_header({- req: req,- res: res,- metaTags: [- { name: 'title', content: returnData.category_name },- { name: 'description', content: returnData.category_description }- ]- }) +- '\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.build_header({+ req: req,+ res: res,+ metaTags: [+ { name: 'title', content: returnData.category_name },+ { name: 'description', content: returnData.category_description }+ ]+ }, function(header) {+ res.send(+ header ++ '\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({ req: req, res: res }) + '<script>templates.ready(function(){ajaxify.go("confirm/' + req.params.code + '");});</script>' + templates['footer']);+ app.build_header({ req: req, res: res }, function(header) {+ res.send(header + '<script>templates.ready(function(){ajaxify.go("confirm/' + req.params.code + '");});</script>' + templates['footer']);+ });});app.get('/sitemap.xml', function(req, res) {@@ -303,10 +324,12 @@ var express = require('express'),var url = req.url.split('?');if (url[1]) {- res.send(app.build_header({ req: req, res: res }) + templates['outgoing'].parse({- url: url[1],- home: global.nconf.get('url')- }) + templates['footer']);+ app.build_header({ req: req, res: res }, function(header) {+ res.send(header + templates['outgoing'].parse({+ url: url[1],+ home: global.nconf.get('url')+ }) + templates['footer']);+ });} else {res.status(404);res.redirect(global.nconf.get('relative_path') + '/404');