Skip to content

Commit

Permalink
Add pre:adminroutes hook
Browse files Browse the repository at this point in the history
Adds a hook which is executed after admin bodyparser but before any admin route.
  • Loading branch information
pixtron committed Feb 25, 2019
1 parent 359b451 commit b638ad7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions admin/server/app/createDynamicRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
3 changes: 2 additions & 1 deletion docs/api/Methods/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down

0 comments on commit b638ad7

Please sign in to comment.