0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/core/server/site/routes.js
Hannah Wolfe abaf0461cf Highlighted routes, controllers & renderers
refs #5091, refs #9192

- There are several theme template "renderers" all over the codebase
- Some are in apps, and were called "controllers"
- One is in error handling
- All of them now have comments marking out how they share logic/steps
- Other comments describe routes & controllers where they live
2017-11-08 09:45:12 +00:00

32 lines
1.3 KiB
JavaScript

var express = require('express'),
config = require('../config'),
controllers = require('../controllers'),
channels = require('../controllers/channels'),
apps = require('../services/route').appRouter,
utils = require('../utils');
module.exports = function siteRouter() {
var router = express.Router(),
routeKeywords = config.get('routeKeywords');
// Admin redirects - register redirect as route
// TODO: this should be middleware!
router.get(/^\/(logout|signout)\/$/, function (req, res) { return utils.url.redirectToAdmin(301, res, '#/signout/'); });
router.get(/^\/signup\/$/, function (req, res) { return utils.url.redirectToAdmin(301, res, '#/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) { return utils.url.redirectToAdmin(301, res, '/'); });
// Preview - register controller as route
router.get(utils.url.urlJoin('/', routeKeywords.preview, ':uuid', ':options?'), controllers.preview);
// Channels - register sub-router
router.use(channels.router());
// Apps - register sub-router
router.use(apps.router);
// Default - register single controller as route
router.get('*', controllers.single);
return router;
};