Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 10 07:02
    hbsjmsjwj opened #1682
  • Aug 10 07:02
    hbsjmsjwj labeled #1682
  • Aug 09 10:20
    zyfyy commented #944
  • Jul 28 01:55
    tkvern closed #1545
  • Jul 22 21:38
    Viiprogrammer edited #1680
  • Jul 22 21:38
    Viiprogrammer edited #1680
  • Jul 22 21:38
    Viiprogrammer edited #1680
  • Jul 22 21:38
    Viiprogrammer edited #1680
  • Jul 22 21:38
    Viiprogrammer edited #1680
  • Jul 22 21:38
    Viiprogrammer edited #1680
  • Jul 22 21:37
    Viiprogrammer opened #1680
  • Jul 22 21:37
    Viiprogrammer labeled #1680
  • Jul 17 08:22
    wenq1 commented #1645
  • Jul 14 09:15
    miwnwski closed #1591
  • Jul 14 09:15
    miwnwski commented #1591
  • Jul 14 09:14
    miwnwski closed #1583
  • Jul 14 09:14
    miwnwski commented #1583
  • Jul 14 09:10
    miwnwski closed #1675
  • Jul 14 09:10
    miwnwski commented #1675
  • Jul 13 16:11

    dependabot[bot] on master

    build(deps-dev): bump jest from… (compare)

David Ojimba
@davidkayce_gitlab
but it does find the post , and it logs the right post to the console
please help anyone?
Jeff Hansen
@jeffijoe
Seems like a promise-related issue, not Koa
David Ojimba
@davidkayce_gitlab
so its a mongoose problem?
Jeff Hansen
@jeffijoe
I don't use Mongoose so I don't know what Promise impl it uses
David Ojimba
@davidkayce_gitlab
oh okay thanks
delphi
@johndeguerto
Do you still need help with this?
David Ojimba
@davidkayce_gitlab
yes, please I do, still havent been able to find a way to resolve it
Samuel Grave
@itsmegrave
hey guys! Do anyone have a list of "must-have" packages for a koa api?
Saad Quadri
@saadq
It really depends on your needs for your api, but at a minimum I would recommend having koa-helmet
Mike Hamilton
@gorbypark
hey guys, noob question here, but can anyone tell me why the body is only [1,2] and not [1,2,3]? I thought middleware flows down, then back up, then the response is sent?
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);
});
Jame
@jamemackson
the body is set on the response before 3 is added to the array. everything after a next is happening on the way back up the middleware stack.
Mike Hamilton
@gorbypark
ah, so it goes down, does the response, then goes up
Casey Britt
@yourfavorite

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.

Jame
@jamemackson
@yourfavorite i would start with https://koajs.com where they give some simple example of middleware in koa
the docs there are pretty simple and that’s simply because koa is pretty simple in what it does.
the one thing to note is that koa calls middleware down and then back up when a await next(); is called. so anything after the next call is happening on the way back up.
Casey Britt
@yourfavorite
@jamemackson I don't quite follow the way down and way back up. Are you saying that Koa goes mw1 -> next() -> mw2 -> await next() -> mw3 -> next() -> mw2 -> ??
Jame
@jamemackson
yes. next passes control down the middleware stack until something sets a response and the flow goes back up executing any code that follows the next call. see the example above that mike posted a day or two ago.
Casey Britt
@yourfavorite
Oh I see
So basically
ctx.before = true;
await next();
// Go do other middlewares...
ctx.after = true;
Jame
@jamemackson
yup. that’s about it.
Casey Britt
@yourfavorite
What is a practical reason for wanting to do this?
Jame
@jamemackson
there are times you want to do something with a response going out. maybe time a response or validate some data
Jackie Gleason
@jrgleason
Can someone help me with koa-jwt. I have it configured but for some reason it is still throwing a 401 even after I am signed in.
Ghost
@ghost~5ac084b8d73408ce4f93eee9
Anyone know how i can modify a specific visitor sessions outside the scope of koa (ctx) ? Getting certain info from Jayson TCP sockets that i want to apply to the correct users session.
Kirk Gordon
@krg7880
Does Koa support keep-alive by default? If not, how can one enable it?
Nicholas
@NicholasCao
Here is a new project. https://github.com/goa-go/goa just like koa for golang, I'm looking for someone to join us.
Eyal Perry
@EyalPerry
@NicholasCao I love the name :D and I do love koa. Unfortunately I do not know go at all
Nicholas
@NicholasCao
@EyalPerry
It doesn't matter, thank you for your start
Aaron
@4aron
Hi
Wow no chat since 1 month...
Can I add an extra arguments to session.save with koa-session?
I want to add some data to the stored session in the same insert
Vamsi Ampolu
@vamsiampolu

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

delphi
@johndeguerto
@vamsiampolu I think headers, methods don’t have setting when an hTTP method is get other than post. So context are executed once upon start of the server. perhaps the app.use( ) where you intialize context to run should be higher in the code chain prior to other middleware?
Vimal Mistry
@vimalmistry
Hello everyone. I want to use Koa for my next project. What is actual real world advantage of koa over express?. I want it for my api backend.
Vimal Mistry
@vimalmistry
Screenshot 2019-09-19 at 11.59.28 PM.png
AuthorizationMiddleware is still calling on first routes why?
delphi
@johndeguerto
@vimalmistry are you having an issue or are you asking why auth is being called in your load routes?
Vimal Mistry
@vimalmistry
@johndeguerto Thanks for reply. I have solved this issue by calling authRoute.use(myMiddleware) :)
Nemo
@gpugems
Hi, what is best npm for koa/health
Kevin
@kevinludwig
Hi, having a problem with setting ctx.body = a stream (sort of). Im using csv-stringify npm module's streams support, so my code is generally doing something like this: ctx.body = stream; await someCodeThatGeneratesCsvRows(stream); stream.end();
I should first say that the code works. The thing that's confusing me is that no rows come to the browser until all rows are generated (e.g. until stream.end() is called). I changed my stream writer to be something a bit more complex, like this, which vaguely what they say to do anyway in the Writable stream docs, const writer = (stream) => (obj) => { return new Promise((resolve) => { if (!stream.write(obj)) { stream.once('drain', resolve); } else { process.nextTick(resolve); } }); };
and when I do that, stream.write does indeed return false at some point but the drain event never arrives, so my request just hangs.
my vague guess is that Im doing something wrong and Koa isn't reading from the stream until .end() but I could be mistaken on that
Kevin
@kevinludwig
ok well I figure out how to get it working...after reading some koa source code. I need to not await someCodeThatGeneratesCsvRows(stream) and instead do ctx.body = stream; someCodeThatReturnsAPromiseThatIWontAwait(stream).then(() => stream.end());
...because Koa doesn't attach the pipe to the stream until after my middleware returns. Is this the way I'm supposed to be doing this? I don't think there's any examples that make this particularly clear in the docs...