mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-08 12:09:43 +03:00
9f9d8b2fec
no issue - This started as an attempt to simplify the admin redirect code - I realised we were sometimes using utils.redirect301 and sometimes not - Decided to move this into utils.url as it's more relevant to URL generation - Unified usage of redirects in the codebase - Updated tests & ensured we have basic coverage - rename adminRedirect -> redirectToAdmin - Tweak method signature, fix channel edit redirects - Tests: Optimised test descriptions for url-redirects_spec.js - ensure caching works as expected
38 lines
1.5 KiB
JavaScript
38 lines
1.5 KiB
JavaScript
var express = require('express'),
|
|
path = require('path'),
|
|
config = require('../config'),
|
|
controllers = require('../controllers'),
|
|
channels = require('../controllers/frontend/channels'),
|
|
utils = require('../utils');
|
|
|
|
module.exports = function frontendRoutes() {
|
|
var router = express.Router(),
|
|
routeKeywords = config.get('routeKeywords');
|
|
|
|
// ### Admin routes
|
|
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, '/'); });
|
|
|
|
// Post Live Preview
|
|
router.get(utils.url.urlJoin('/', routeKeywords.preview, ':uuid', ':options?'), controllers.preview);
|
|
|
|
// Channels
|
|
router.use(channels.router());
|
|
|
|
// setup routes for internal apps
|
|
// @TODO: refactor this to be a proper app route hook for internal & external apps
|
|
config.get('apps:internal').forEach(function (appName) {
|
|
var app = require(path.join(config.get('paths').internalAppPath, appName));
|
|
if (app.hasOwnProperty('setupRoutes')) {
|
|
app.setupRoutes(router);
|
|
}
|
|
});
|
|
|
|
// Default
|
|
router.get('*', controllers.single);
|
|
|
|
return router;
|
|
};
|