mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
Moved admin redirect middleware to named file
- moving this middleware because we're about to add a second piece of middleware - it's easier to see what we have when each middleware is in its own file rather than in one big middleware.js file
This commit is contained in:
parent
d92eebd74e
commit
621cfd9866
@ -5,7 +5,7 @@ const config = require('../../../shared/config');
|
||||
const constants = require('@tryghost/constants');
|
||||
const urlUtils = require('../../../shared/url-utils');
|
||||
const shared = require('../shared');
|
||||
const adminMiddleware = require('./middleware');
|
||||
const redirectAdminUrls = require('./middleware/redirect-admin-urls');
|
||||
|
||||
module.exports = function setupAdminApp() {
|
||||
debug('Admin setup start');
|
||||
@ -39,7 +39,7 @@ module.exports = function setupAdminApp() {
|
||||
adminApp.use(shared.middleware.cacheControl('private'));
|
||||
|
||||
// Special redirects for the admin (these should have their own cache-control headers)
|
||||
adminApp.use(adminMiddleware);
|
||||
adminApp.use(redirectAdminUrls);
|
||||
|
||||
// Finally, routing
|
||||
adminApp.get('*', require('./controller'));
|
||||
|
15
core/server/web/admin/middleware/redirect-admin-urls.js
Normal file
15
core/server/web/admin/middleware/redirect-admin-urls.js
Normal file
@ -0,0 +1,15 @@
|
||||
const urlUtils = require('../../../../shared/url-utils');
|
||||
|
||||
function redirectAdminUrls(req, res, next) {
|
||||
const subdir = urlUtils.getSubdir();
|
||||
const ghostPathRegex = new RegExp(`^${subdir}/ghost/(.+)`);
|
||||
const ghostPathMatch = req.originalUrl.match(ghostPathRegex);
|
||||
|
||||
if (ghostPathMatch) {
|
||||
return res.redirect(urlUtils.urlJoin(urlUtils.urlFor('admin'), '#', ghostPathMatch[1]));
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = redirectAdminUrls;
|
@ -2,7 +2,7 @@ const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
|
||||
// Thing we are testing
|
||||
const redirectAdminUrls = require('../../../../../core/server/web/admin/middleware')[0];
|
||||
const redirectAdminUrls = require('../../../../../core/server/web/admin/middleware/redirect-admin-urls');
|
||||
|
||||
describe('Admin App', function () {
|
||||
afterEach(function () {
|
||||
|
Loading…
Reference in New Issue
Block a user