(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);
});
});
};
request.req()
generates a huge object. Is there any more efficient way to just get the body's chunks? There seems to be a lot of overhead just from that one call. Would be awesome to be able to avoid it.