dependabot[bot] on master
build(deps-dev): bump jest from… (compare)
let post_promise = Post.findOne({ title: 'First post' }).exec()
await post_promise.then((result) => {
console.log(result)
ctx.body = result
ctx.status = 200
}).catch((err) => {
console.log(err)
})
console.log('Gotten here')
app.use(async (ctx, next) => {
arr.push(1);
await next();
arr.push(3);
});
app.use(async (ctx, next) => {
arr.push(2);
await next();
});
app.use(async ctx => {
ctx.body = JSON.stringify(arr);
});
Anyone able to help me better understand a Middleware pattern? I'm wondering if there is an article or tutorial out there about how to add Middlewares to your own code rather than writing Middlewares for existing packages. Or even just one that breaksdown how Middlewares work in something like Koa. Searching google just gets me info on how to write better middelwares for things like Koa/Express.
I'm particularly interested in the pattern Koa uses with context and would love an article that pulls the general flow out into some easier to comprehend code as jumping through the many koa packages is difficult for me to follow.
await next();
is called. so anything after the next call is happening on the way back up.
ctx.before = true;
await next();
// Go do other middlewares...
ctx.after = true;
Hi guys, a question for you:
tl;dr: Trying to create a mock context like this:
const ctx = createContext({
method,
headers,
body,
});
throws TypeErrors
https://stackoverflow.com/questions/57864117/koa-create-context-cannot-set-headers-or-body