Adding express.js middleware to keystone

519 views
Skip to first unread message

Raphael V.

unread,
Nov 19, 2014, 9:12:04 AM11/19/14
to keyst...@googlegroups.com
Hi

I am new to both Node.js and Keystone, and so far I really like it! Please excuse me if the answer to this question is obvious.

Is it possible to add middleware to the keystone's express app? I know I can provide my own express app to keystone, but all I want is to add this form verification middleware to the express.js app: https://github.com/ctavan/express-validator

Can someone point me in the right direction? Any help is greatly appreciated.

Raphael

atlb...@gmail.com

unread,
Nov 23, 2014, 5:02:08 AM11/23/14
to keyst...@googlegroups.com
I have not tested this but you can give it a shot.  I have a suspicion it may hit too late it the "immediate" in the instructions really means Immediately after:
app.use(expressValidator([options])); // this line must be immediately after express.bodyParser()!


var keystone = require('keystone'),
   
expressValidator = require('express-validator');

...
set up keystone
...

keystone
.start({
   onMount
: function() {
       keystone
.app.use(expressValidator([options]));
   
}
});


Adding your own express app isn't difficult if any else who reads this is interested and most of the info you need to mimic the Keystone express setup is in
keystone/lib/core/mount.js

A simple custom setup can look like
keystone.connect(app);
keystone.init();
keystone.mount({
onMount: function() {
console.log('mounted');
}
});




Reply all
Reply to author
Forward
0 new messages