Ghost/core/server/routes/frontend.js
Katie Fenn 980b0a8610 Refactoring hard-coded frontend route keywords
closes #4519

- Added configurable route keywords
- Replaced instances of hard-coded keywords with config
- Added keywords to frontend tests stub config
2015-03-23 15:00:02 +00:00

60 lines
2.3 KiB
JavaScript

var frontend = require('../controllers/frontend'),
config = require('../config'),
express = require('express'),
utils = require('../utils'),
frontendRoutes;
frontendRoutes = function () {
var router = express.Router(),
subdir = config.paths.subdir;
// ### Admin routes
router.get(/^\/(logout|signout)\/$/, function redirect(req, res) {
/*jslint unparam:true*/
res.set({'Cache-Control': 'public, max-age=' + utils.ONE_YEAR_S});
res.redirect(301, subdir + '/ghost/signout/');
});
router.get(/^\/signup\/$/, function redirect(req, res) {
/*jslint unparam:true*/
res.set({'Cache-Control': 'public, max-age=' + utils.ONE_YEAR_S});
res.redirect(301, subdir + '/ghost/signup/');
});
// redirect to /ghost and let that do the authentication to prevent redirects to /ghost//admin etc.
router.get(/^\/((ghost-admin|admin|wp-admin|dashboard|signin|login)\/?)$/, function (req, res) {
/*jslint unparam:true*/
res.redirect(subdir + '/ghost/');
});
// ### Frontend routes
router.get('/rss/', frontend.rss);
router.get('/rss/:page/', frontend.rss);
router.get('/feed/', function redirect(req, res) {
/*jshint unused:true*/
res.set({'Cache-Control': 'public, max-age=' + utils.ONE_YEAR_S});
res.redirect(301, subdir + '/rss/');
});
// Tags
router.get('/' + config.routeKeywords.tag + '/:slug/rss/', frontend.rss);
router.get('/' + config.routeKeywords.tag + '/:slug/rss/:page/', frontend.rss);
router.get('/' + config.routeKeywords.tag + '/:slug/' + config.routeKeywords.page + '/:page/', frontend.tag);
router.get('/' + config.routeKeywords.tag + '/:slug/', frontend.tag);
// Authors
router.get('/' + config.routeKeywords.author + '/:slug/rss/', frontend.rss);
router.get('/' + config.routeKeywords.author + '/:slug/rss/:page/', frontend.rss);
router.get('/' + config.routeKeywords.author + '/:slug/' + config.routeKeywords.page + '/:page/', frontend.author);
router.get('/' + config.routeKeywords.author + '/:slug/', frontend.author);
// Default
router.get('/' + config.routeKeywords.page + '/:page/', frontend.homepage);
router.get('/', frontend.homepage);
router.get('*', frontend.single);
return router;
};
module.exports = frontendRoutes;