mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
13c1742eb9
refs #5091 - Move renderChannel to own file - Update channel config to have get/list methods - Move main routes to be generated based on the list of channels - Move RSS routes to be subroutes of channels - Move redirect301 to be a shared util - Add full test coverage - Split frontend route tests into frontend & channels
57 lines
1.8 KiB
JavaScript
57 lines
1.8 KiB
JavaScript
var frontend = require('../controllers/frontend'),
|
|
channels = require('../controllers/frontend/channels'),
|
|
config = require('../config'),
|
|
express = require('express'),
|
|
utils = require('../utils'),
|
|
|
|
frontendRoutes;
|
|
|
|
frontendRoutes = function frontendRoutes(middleware) {
|
|
var router = express.Router(),
|
|
subdir = config.paths.subdir,
|
|
routeKeywords = config.routeKeywords,
|
|
privateRouter = express.Router();
|
|
|
|
// ### Admin routes
|
|
router.get(/^\/(logout|signout)\/$/, function redirectToSignout(req, res) {
|
|
utils.redirect301(res, subdir + '/ghost/signout/');
|
|
});
|
|
router.get(/^\/signup\/$/, function redirectToSignup(req, res) {
|
|
utils.redirect301(res, 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 redirectToAdmin(req, res) {
|
|
utils.redirect301(res, subdir + '/ghost/');
|
|
});
|
|
|
|
// password-protected frontend route
|
|
privateRouter.route('/')
|
|
.get(
|
|
middleware.privateBlogging.isPrivateSessionAuth,
|
|
frontend.private
|
|
)
|
|
.post(
|
|
middleware.privateBlogging.isPrivateSessionAuth,
|
|
middleware.spamPrevention.protected,
|
|
middleware.privateBlogging.authenticateProtection,
|
|
frontend.private
|
|
);
|
|
|
|
// Post Live Preview
|
|
router.get('/' + routeKeywords.preview + '/:uuid', frontend.preview);
|
|
|
|
// Private
|
|
router.use('/' + routeKeywords.private + '/', privateRouter);
|
|
|
|
// Channels
|
|
router.use(channels.router());
|
|
|
|
// Default
|
|
router.get('*', frontend.single);
|
|
|
|
return router;
|
|
};
|
|
|
|
module.exports = frontendRoutes;
|