Syncano Middleware
Syncano middleware provide a convenient mechanism for filtering HTTP requests entering your socket. For example validate passed parameters, check if user is authenticated, assign default parameter values and many more.
For full list of middlewares check NPM.
Getting started
Installing from NPM
npm install syncano-middleware --save
Usage
import middleware from 'syncano-middleware';
const steps = {
auth: () => new Promise((resolve, reject) => {
resolve(user)
}),
validate: () => new Promise((resolve, reject) => {
resolve(formFields)
})
}
middleware([ steps.auth, steps.validate ])
.then(data => {
const [ user, fields ] = data
})
.const(err => {
})
Custom middlewares
Middleware must be a function that returns a Promise:
function MyAwesomeMiddleware() {
return new Promise((resolve, reject) => {
})
}