Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exress validator #66

Closed
x0y4053 opened this issue Dec 13, 2013 · 1 comment
Closed

exress validator #66

x0y4053 opened this issue Dec 13, 2013 · 1 comment

Comments

@x0y4053
Copy link

x0y4053 commented Dec 13, 2013

Hi, I am working with Sujana in Paypal professional service.
I am trying to use express validator with Kraken.
I have downloaded express validator. How can I configure it with Kraken?
I am looking at app.json file but not sure what the syntax should be.
Thank you,

Vivian Yu
Developer
viyu@paypal.com

@lmarkus
Copy link
Contributor

lmarkus commented Dec 13, 2013

Hi Vivian,
Take a look at
https://github.com/lensam69/Kraken_Example_Custom_Middleware and
https://github.com/lmarkus/Kraken_Example_Configuration
for inspiration.

There are three things you want to do:

  1. Add any custom configuration to ./config/middleware.json under a key which you will retrieve later (eg express-valitador)
  2. In your application entry point (most likely ./index.js) you should require it var expressValidator = require('express-validator').
  3. During the configuration hook, you can create the middleware function, and pass the configuration (if any) (I'd store it in the same variable for convenience):
app.configure = function configure(nconf, next) {
    // Fired when an app configures itself
    expressValidator = expressValidator(nconf.get('express-validator'));
    next(null);
};
  1. Tell the application to use it within the requestBeforeRoute hook. This hook is invoked only once, after the base middleware for Kraken has been set up.
app.requestBeforeRoute = function requestBeforeRoute(server) {
    server.use(expressValidator);
};

NOTE: I read in the express-validator site that it needs to be used right after using the bodyParser middleware (Which we don't use, we use multipart). I don't know if this will affect you.

@lmarkus lmarkus closed this as completed Dec 13, 2013
t0lkman pushed a commit to t0lkman/kraken-js that referenced this issue Feb 6, 2014
organize express settings, keeping support for old ones
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants