diff --git a/core/frontend/services/routing/controllers/entry.js b/core/frontend/services/routing/controllers/entry.js index bd336eefb0..e1803266d0 100644 --- a/core/frontend/services/routing/controllers/entry.js +++ b/core/frontend/services/routing/controllers/entry.js @@ -40,7 +40,7 @@ module.exports = function entryController(req, res, next) { } debug('redirect. is edit url'); - const resourceType = entry.page ? 'page' : 'post'; + const resourceType = res.routerOptions?.context?.includes('page') ? 'page' : 'post'; return urlUtils.redirectToAdmin(302, res, `/#/editor/${resourceType}/${entry.id}`); } diff --git a/test/regression/site/frontend.test.js b/test/regression/site/frontend.test.js index 5bf23530e0..39e3c8f01a 100644 --- a/test/regression/site/frontend.test.js +++ b/test/regression/site/frontend.test.js @@ -156,28 +156,32 @@ describe('Frontend Routing', function () { }); describe('edit', function () { - it('should redirect without slash', function (done) { - request.get('/static-page-test/edit') + it('should redirect without slash', async function () { + await request.get('/static-page-test/edit') .expect('Location', '/static-page-test/edit/') .expect('Cache-Control', testUtils.cacheRules.year) - .expect(301) - .end(doEnd(done)); + .expect(301); }); - it('should redirect to editor', function (done) { - request.get('/static-page-test/edit/') - .expect('Location', /ghost\/#\/editor\/\w+/) + it('should redirect to editor for post resource', async function () { + await request.get('//welcome/edit/') + .expect('Location', /ghost\/#\/editor\/post\/\w+/) .expect('Cache-Control', testUtils.cacheRules.public) - .expect(302) - .end(doEnd(done)); + .expect(302); }); - it('should 404 for non-edit parameter', function (done) { - request.get('/static-page-test/notedit/') + it('should redirect to editor for page resource', async function () { + await request.get('/static-page-test/edit/') + .expect('Location', /ghost\/#\/editor\/page\/\w+/) + .expect('Cache-Control', testUtils.cacheRules.public) + .expect(302); + }); + + it('should 404 for non-edit parameter', async function () { + await request.get('/static-page-test/notedit/') .expect('Cache-Control', testUtils.cacheRules.private) .expect(404) - .expect(/Page not found/) - .end(doEnd(done)); + .expect(/Page not found/); }); });