mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Move admin redirects out of site router
refs #9192 - Admin redirects should really happen first, up with custom redirects - Later we can package this up, maybe - For now, let's focus the site router on site-related things
This commit is contained in:
parent
abaf0461cf
commit
187c38991e
3 changed files with 24 additions and 7 deletions
21
core/server/middleware/admin-redirects.js
Normal file
21
core/server/middleware/admin-redirects.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
var express = require('express'),
|
||||
utils = require('../utils'),
|
||||
adminRedirect;
|
||||
|
||||
adminRedirect = function adminRedirect(path) {
|
||||
return function doRedirect(req, res) {
|
||||
return utils.url.redirectToAdmin(301, res, path);
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = function adminRedirects() {
|
||||
var router = express.Router();
|
||||
// Admin redirects - register redirect as route
|
||||
// TODO: this should be middleware!
|
||||
router.get(/^\/(logout|signout)\/$/, adminRedirect('#/signout/'));
|
||||
router.get(/^\/signup\/$/, adminRedirect('#/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)\/?)$/, adminRedirect('/'));
|
||||
|
||||
return router;
|
||||
};
|
|
@ -26,6 +26,7 @@ var debug = require('ghost-ignition').debug('blog'),
|
|||
staticTheme = require('../middleware/static-theme'),
|
||||
customRedirects = require('../middleware/custom-redirects'),
|
||||
serveFavicon = require('../middleware/serve-favicon'),
|
||||
adminRedirects = require('../middleware/admin-redirects'),
|
||||
|
||||
// middleware for themes
|
||||
themeMiddleware = require('../themes').middleware;
|
||||
|
@ -42,6 +43,8 @@ module.exports = function setupSiteApp() {
|
|||
// you can extend Ghost with a custom redirects file
|
||||
// see https://github.com/TryGhost/Ghost/issues/7707
|
||||
customRedirects.use(siteApp);
|
||||
// More redirects
|
||||
siteApp.use(adminRedirects());
|
||||
|
||||
// Static content/assets
|
||||
// @TODO make sure all of these have a local 404 error handler
|
||||
|
|
|
@ -9,13 +9,6 @@ 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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue