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

Adding Express Validator #36

Closed
Radagaisus opened this issue Aug 30, 2012 · 1 comment
Closed

Adding Express Validator #36

Radagaisus opened this issue Aug 30, 2012 · 1 comment
Labels

Comments

@Radagaisus
Copy link

Hey,

I'm thinking about adding Express Validator to Zappa. I wrote a blog post about the sugar I'm using to make it nice.

Adding it straight into zappa will make two functions available @assert and @sanitize. I can also add support for socket.io.

Any thoughts on how the API should look like?

@get '/health', ->
  @on_error = @next # This is the error handler,
                                   # if asserting goes wrong, next()
                                   # is the default express error handler,
                                   # and @on_error should be equal to
                                   # next by default
  @pre =>
    @assert('param', 'Invalid Param').notEmpty()
  , =>
    # Validation Passed
    @response.json
      pid: process.pid
      memory: process.memoryUsage()
      uptime: process.uptime()

Also: the github fork this project link in Zappa's website is broken, and leads to the wrong repo.

@shimaore
Copy link
Member

It should be possible to make it into your own zappajs plugin and publish it.

require('zappajs') ->
  @include require('zappajs-validator')

Plugin would look something like:

# zappajs-validator
@include = ->
  @use 'express-validator'
  @helper pre: (fn) ->
      error_handler = fn()
      errors = @req.validationErrors()
      if errors then error_handler(errors)
      else @next()

Unless I'm missing a piece where this needs to deal with Zappa internals?

@shimaore shimaore mentioned this issue Sep 3, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants