diff --git a/admin/server/app/createDynamicRouter.js b/admin/server/app/createDynamicRouter.js index 2128aca46a..c00b5c087d 100644 --- a/admin/server/app/createDynamicRouter.js +++ b/admin/server/app/createDynamicRouter.js @@ -26,6 +26,14 @@ module.exports = function createDynamicRouter (keystone) { next(); }); + // Pre adminroutes middleware + if (typeof keystone.get('pre:adminroutes') === 'function') { + keystone.get('pre:adminroutes')(router); + } + router.use(function (req, res, next) { + keystone.callHook('pre:adminroutes', req, res, next); + }); + if (keystone.get('healthchecks')) { router.use('/server-health', require('./createHealthchecksHandler')(keystone)); } diff --git a/docs/api/Methods/middleware.md b/docs/api/Methods/middleware.md index 44c27f3f1f..9510ff8889 100644 --- a/docs/api/Methods/middleware.md +++ b/docs/api/Methods/middleware.md @@ -15,7 +15,8 @@ name | call time `pre:bodyparser` | `pre:session` | `pre:admin` | -`pre:routes` | Installs Express middleware which is called before each route is executed. +`pre:adminroutes` | Installs Express middleware which is called before each admin route is executed. +`pre:routes` | Installs Express middleware which is called before each non admin route is executed. `pre:render` | Called before a Keystone [view](/api/view) is rendered. `updates` | `signin` | Called before a user signs in to the Keystone admin UI and the user is returned a view. diff --git a/index.js b/index.js index 29dfcb66e4..d87aa64023 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,7 @@ var moduleRoot = (function (_rootPath) { * Keystone Class */ var Keystone = function () { - grappling.mixin(this).allowHooks('pre:static', 'pre:bodyparser', 'pre:session', 'pre:logger', 'pre:admin', 'pre:routes', 'pre:render', 'updates', 'signin', 'signout'); + grappling.mixin(this).allowHooks('pre:static', 'pre:bodyparser', 'pre:session', 'pre:logger', 'pre:admin', 'pre:adminroutes', 'pre:routes', 'pre:render', 'updates', 'signin', 'signout'); this.lists = {}; this.fieldTypes = {}; this.paths = {};