Skip to content

Mali middleware that automatically calls toObject on response

License

Notifications You must be signed in to change notification settings

malijs/toobject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@malijs/toobject

Mali toObject middleware. If the response object has a toObject function it's executed upon payload. Only applies for UNARY and REQUEST_STREAM call types.

Example

const toObject = require('@malijs/toobject')

function handler(ctx) {
  const obj = {
    email: 'bob@gmail.com',
    password: 'mysecret'
  }

  obj.toObject = function() {
    return {
      email: this.email
    }
  }

  ctx.res = obj // password will not be in the payload to client
}

app.use('fn', toObject(), handler)

About

Mali middleware that automatically calls toObject on response

Resources

License

Stars

Watchers

Forks

Packages

No packages published