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

33 lines
1.3 KiB
JavaScript
Raw Normal View History

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;
};