mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Renamed redirect functions for clarity
- we had urlRedirects, urlRedirects.adminRedirect and adminRedirects - all do kinda similar things, but for different contexts so for now I've done a minimal renaming for clarity - and updated some comments!! - also removed totally unnecessary if res.isAdmin clause, as we don't use that, and it was never true
This commit is contained in:
parent
ca0f4635c9
commit
19dde146c1
10 changed files with 23 additions and 38 deletions
|
@ -37,7 +37,7 @@ module.exports = function setupAdminApp() {
|
|||
|
||||
// Force SSL if required
|
||||
// must happen AFTER asset loading and BEFORE routing
|
||||
adminApp.use(shared.middlewares.urlRedirects.adminRedirect);
|
||||
adminApp.use(shared.middlewares.urlRedirects.adminSSLAndHostRedirect);
|
||||
|
||||
// Add in all trailing slashes & remove uppercase
|
||||
// must happen AFTER asset loading and BEFORE routing
|
||||
|
|
|
@ -55,7 +55,7 @@ module.exports.authAdminApi = [
|
|||
auth.authorize.authorizeAdminApi,
|
||||
apiMw.updateUserLastSeen,
|
||||
apiMw.cors,
|
||||
shared.middlewares.urlRedirects.adminRedirect,
|
||||
shared.middlewares.urlRedirects.adminSSLAndHostRedirect,
|
||||
shared.middlewares.prettyUrls,
|
||||
notImplemented
|
||||
];
|
||||
|
@ -69,7 +69,7 @@ module.exports.authAdminApiWithUrl = [
|
|||
auth.authorize.authorizeAdminApi,
|
||||
apiMw.updateUserLastSeen,
|
||||
apiMw.cors,
|
||||
shared.middlewares.urlRedirects.adminRedirect,
|
||||
shared.middlewares.urlRedirects.adminSSLAndHostRedirect,
|
||||
shared.middlewares.prettyUrls,
|
||||
notImplemented
|
||||
];
|
||||
|
@ -79,7 +79,7 @@ module.exports.authAdminApiWithUrl = [
|
|||
*/
|
||||
module.exports.publicAdminApi = [
|
||||
apiMw.cors,
|
||||
shared.middlewares.urlRedirects.adminRedirect,
|
||||
shared.middlewares.urlRedirects.adminSSLAndHostRedirect,
|
||||
shared.middlewares.prettyUrls,
|
||||
notImplemented
|
||||
];
|
||||
|
|
|
@ -18,6 +18,6 @@ module.exports.authenticatePublic = [
|
|||
auth.authenticate.authenticateContentApi,
|
||||
auth.authorize.authorizeContentApi,
|
||||
cors(),
|
||||
shared.middlewares.urlRedirects.adminRedirect,
|
||||
shared.middlewares.urlRedirects.adminSSLAndHostRedirect,
|
||||
shared.middlewares.prettyUrls
|
||||
];
|
||||
|
|
|
@ -52,7 +52,7 @@ module.exports.authAdminApi = [
|
|||
auth.authorize.authorizeAdminApi,
|
||||
apiMw.updateUserLastSeen,
|
||||
apiMw.cors,
|
||||
shared.middlewares.urlRedirects.adminRedirect,
|
||||
shared.middlewares.urlRedirects.adminSSLAndHostRedirect,
|
||||
shared.middlewares.prettyUrls,
|
||||
notImplemented
|
||||
];
|
||||
|
@ -66,7 +66,7 @@ module.exports.authAdminApiWithUrl = [
|
|||
auth.authorize.authorizeAdminApi,
|
||||
apiMw.updateUserLastSeen,
|
||||
apiMw.cors,
|
||||
shared.middlewares.urlRedirects.adminRedirect,
|
||||
shared.middlewares.urlRedirects.adminSSLAndHostRedirect,
|
||||
shared.middlewares.prettyUrls,
|
||||
notImplemented
|
||||
];
|
||||
|
@ -76,7 +76,7 @@ module.exports.authAdminApiWithUrl = [
|
|||
*/
|
||||
module.exports.publicAdminApi = [
|
||||
apiMw.cors,
|
||||
shared.middlewares.urlRedirects.adminRedirect,
|
||||
shared.middlewares.urlRedirects.adminSSLAndHostRedirect,
|
||||
shared.middlewares.prettyUrls,
|
||||
notImplemented
|
||||
];
|
||||
|
|
|
@ -18,6 +18,6 @@ module.exports.authenticatePublic = [
|
|||
auth.authenticate.authenticateContentApi,
|
||||
auth.authorize.authorizeContentApi,
|
||||
cors(),
|
||||
shared.middlewares.urlRedirects.adminRedirect,
|
||||
shared.middlewares.urlRedirects.adminSSLAndHostRedirect,
|
||||
shared.middlewares.prettyUrls
|
||||
];
|
||||
|
|
|
@ -111,17 +111,13 @@ _private.redirect = (req, res, next, redirectFn) => {
|
|||
next();
|
||||
};
|
||||
|
||||
/*
|
||||
* @deprecated: in favor of adminRedirect (extract public getBlogRedirectUrl method when needed)
|
||||
*/
|
||||
const urlRedirects = (req, res, next) => {
|
||||
const redirectFn = res.isAdmin ? _private.getAdminRedirectUrl : _private.getBlogRedirectUrl;
|
||||
_private.redirect(req, res, next, redirectFn);
|
||||
const frontendRedirect = (req, res, next) => {
|
||||
_private.redirect(req, res, next, _private.getBlogRedirectUrl);
|
||||
};
|
||||
|
||||
const adminRedirect = (req, res, next) => {
|
||||
_private.redirect(req, res, next, _private.getAdminRedirectUrl);
|
||||
};
|
||||
|
||||
module.exports = urlRedirects;
|
||||
module.exports.adminRedirect = adminRedirect;
|
||||
module.exports.frontendSSLRedirect = frontendRedirect;
|
||||
module.exports.adminSSLAndHostRedirect = adminRedirect;
|
||||
|
|
|
@ -96,12 +96,12 @@ module.exports = function setupSiteApp(options = {}) {
|
|||
// see https://github.com/TryGhost/Ghost/issues/7707
|
||||
shared.middlewares.customRedirects.use(siteApp);
|
||||
|
||||
// More redirects
|
||||
siteApp.use(mw.adminRedirects());
|
||||
// (Optionally) redirect any requests to /ghost to the admin panel
|
||||
siteApp.use(mw.redirectGhostToAdmin());
|
||||
|
||||
// force SSL if blog url is set to https. The redirects handling must happen before asset and page routing,
|
||||
// otherwise we serve assets/pages with http. This can cause mixed content warnings in the admin client.
|
||||
siteApp.use(shared.middlewares.urlRedirects);
|
||||
siteApp.use(shared.middlewares.urlRedirects.frontendSSLRedirect);
|
||||
|
||||
// Static content/assets
|
||||
// @TODO make sure all of these have a local 404 error handler
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = {
|
||||
adminRedirects: require('./admin-redirects'),
|
||||
handleImageSizes: require('./handle-image-sizes'),
|
||||
redirectGhostToAdmin: require('./redirect-ghost-to-admin'),
|
||||
serveFavicon: require('./serve-favicon'),
|
||||
servePublicFile: require('./serve-public-file'),
|
||||
staticTheme: require('./static-theme')
|
||||
|
|
|
@ -9,11 +9,9 @@ const adminRedirect = (path) => {
|
|||
};
|
||||
|
||||
// redirect to /ghost to the admin
|
||||
module.exports = function adminRedirects() {
|
||||
module.exports = function redirectGhostToAdmin() {
|
||||
const router = express.Router();
|
||||
|
||||
console.log('loading admin redirects');
|
||||
|
||||
if (config.get('admin:redirects')) {
|
||||
router.get(/^\/ghost\/?$/, adminRedirect('/'));
|
||||
}
|
|
@ -3,7 +3,7 @@ var should = require('should'),
|
|||
rewire = require('rewire'),
|
||||
urlUtils = require('../../../utils/urlUtils'),
|
||||
urlRedirects = rewire('../../../../core/server/web/shared/middlewares/url-redirects'),
|
||||
{adminRedirect} = urlRedirects,
|
||||
{frontendSSLRedirect, adminSSLAndHostRedirect} = urlRedirects,
|
||||
getAdminRedirectUrl = urlRedirects.__get__('_private.getAdminRedirectUrl'),
|
||||
getBlogRedirectUrl = urlRedirects.__get__('_private.getBlogRedirectUrl'),
|
||||
redirect = urlRedirects.__get__('_private.redirect');
|
||||
|
@ -38,27 +38,18 @@ describe('UNIT: url redirects', function () {
|
|||
urlRedirects.__set__('_private.redirect', redirectSpy);
|
||||
});
|
||||
|
||||
it('urlRedirects passes getAdminRedirectUrl method when iAdmin flag is not set', function () {
|
||||
it('frontendSSLRedirect passes getBlogRedirectUrl', function () {
|
||||
urlRedirects.__set__('urlUtils', urlUtils.getInstance({url: 'https://default.com:2368/'}));
|
||||
|
||||
urlRedirects(req, res, next);
|
||||
frontendSSLRedirect(req, res, next);
|
||||
|
||||
redirectSpy.calledWith(req, res, next, getBlogRedirectUrl).should.eql(true);
|
||||
});
|
||||
|
||||
it('urlRedirects passes getAdminRedirectUrl method when iAdmin flag present', function () {
|
||||
res.isAdmin = true;
|
||||
it('adminSSLAndHostRedirect passes getAdminRedirectUrl', function () {
|
||||
urlRedirects.__set__('urlUtils', urlUtils.getInstance({url: 'https://default.com:2368/'}));
|
||||
|
||||
urlRedirects(req, res, next);
|
||||
|
||||
redirectSpy.calledWith(req, res, next, getAdminRedirectUrl).should.eql(true);
|
||||
});
|
||||
|
||||
it('adminRedirect passes getAdminRedirectUrl', function () {
|
||||
urlRedirects.__set__('urlUtils', urlUtils.getInstance({url: 'https://default.com:2368/'}));
|
||||
|
||||
adminRedirect(req, res, next);
|
||||
adminSSLAndHostRedirect(req, res, next);
|
||||
|
||||
redirectSpy.calledWith(req, res, next, getAdminRedirectUrl).should.eql(true);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue