robots + sitemap; some clean up

v1.18.x
psychobunny 11 years ago
parent 942d16a3b4
commit 00df660fa5

@ -1,11 +1,12 @@
var topicsController = require('./topics'),
categoriesController = require('./categories'),
async = require('async'),
auth = require('../routes/authentication'),
meta = require('../meta'),
plugins = require('../plugins'),
categories = require('../categories'),
categoryTools = require('../categoryTools');
nconf = require('nconf'),
auth = require('./../routes/authentication'),
meta = require('./../meta'),
plugins = require('./../plugins'),
categories = require('./../categories'),
categoryTools = require('./../categoryTools');
@ -164,4 +165,25 @@ Controllers.confirmEmail = function(req, res, next) {
});
};
Controllers.sitemap = function(req, res, next) {
var sitemap = require('./../sitemap.js');
sitemap.render(function(xml) {
res.header('Content-Type', 'application/xml');
res.send(xml);
});
};
Controllers.robots = function (req, res) {
res.set('Content-Type', 'text/plain');
if (meta.config["robots.txt"]) {
res.send(meta.config["robots.txt"]);
} else {
res.send("User-agent: *\n" +
"Disallow: /admin/\n" +
"Sitemap: " + nconf.get('url') + "/sitemap.xml");
}
};
module.exports = Controllers;

@ -629,6 +629,10 @@ process.on('uncaughtException', function(err) {
app.get('/confirm/:code', app.buildHeader, controllers.confirmEmail);
app.get('/api/confirm/:code', app.prepareAPI, controllers.confirmEmail);
app.get('/sitemap.xml', controllers.sitemap);
app.get('/robots.txt', controllers.robots);
/* Topics */
app.get('/topic/:topic_id/:slug?', app.buildHeader, controllers.topics.get);
app.get('/api/topic/:topic_id/:slug?', app.prepareAPI, controllers.topics.get);
@ -649,56 +653,7 @@ process.on('uncaughtException', function(err) {
app.get('/category/:category_id/:slug?', app.buildHeader, controllers.categories.get);
app.get('/api/category/:category_id/:slug?', app.prepareAPI, controllers.categories.get);
app.get('/confirm/:code', function (req, res) {
app.build_header({
req: req,
res: res
}, function (err, header) {
res.send(header + app.create_route('confirm/' + req.params.code) + templates.footer);
});
});
app.get('/sitemap.xml', function (req, res) {
var sitemap = require('./sitemap.js');
sitemap.render(function (xml) {
res.header('Content-Type', 'application/xml');
res.send( xml );
});
});
app.get('/robots.txt', function (req, res) {
res.set('Content-Type', 'text/plain');
if (meta.config["robots.txt"]) {
res.send(meta.config["robots.txt"])
} else {
res.send("User-agent: *\n" +
"Disallow: /admin/\n" +
"Sitemap: " + nconf.get('url') + "/sitemap.xml");
}
});
/*app.get('/recent/:term?', function (req, res) {
// TODO consolidate with /recent route as well -> that can be combined into this area. See "Basic Routes" near top.
app.build_header({
req: req,
res: res
}, function (err, header) {
res.send(header + app.create_route('recent/' + req.params.term, null, 'recent') + templates.footer);
});
});*/
/*app.get('/popular/:term?', function (req, res) {
app.build_header({
req: req,
res: res
}, function (err, header) {
res.send(header + app.create_route('popular/' + req.params.term, null, 'popular') + templates.footer);
});
});*/
app.get('/outgoing', function (req, res) {
if (!req.query.url) {

Loading…
Cancel
Save