(handler) => {
return async (request) => {
const userExists = await calltoDB(request.user)
if (!userExists) // return "you have to login!" immediately to client
return handler(request)
}
}
{ status: 123, headers: { ... }, body: "..." }
you get it? but people might find writing it the manual way tedious so that's why i included functions for creating it like response()
(handler) => { // <---- spirit calls this function
return async (request) => { // <-- this is the result of handler(request) / the previous middleware
const userExists = await calltoDB(request.user)
if (!userExists) return response("you have to login!")
return handler(request)
}
}
sendDate
property which you can set to false to disable this header. Don't recall how to access the vanilla response with spirit though, @hnry?
export default handler => request => {
return new Promise((resolve, reject) => {
const req = request.req();
const chunks = [];
req.on('data', data => {
chunks.push(data.toString());
});
req.on('end', () => {
request.body = chunks.join('');
console.log(request.body);
resolve(request);
});
});
};