Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 22 00:12
    tomknappramos commented #1337
  • Sep 17 09:01
    fl0w commented #1383
  • Sep 17 02:31
    libook commented #1114
  • Sep 17 02:27
    libook opened #1383
  • Sep 11 17:23
    gatsbyz commented #1381
  • Sep 11 16:19
    dead-horse closed #1381
  • Sep 11 16:19
    dead-horse commented #1381
  • Sep 11 15:21
    gatsbyz commented #1381
  • Sep 11 15:20
    dead-horse commented #1381
  • Sep 11 14:50
    fl0w reopened #1381
  • Sep 11 14:16
    gatsbyz commented #1381
  • Sep 11 14:15
    gatsbyz commented #1381
  • Sep 11 12:50
    fl0w commented #1382
  • Sep 11 08:25
    paramsinghvc commented #1382
  • Sep 11 08:02
    fl0w commented #1382
  • Sep 11 07:59
    fl0w commented #1382
  • Sep 11 07:52
    fl0w commented #1382
  • Sep 11 07:50
    fl0w commented #1382
  • Sep 11 07:05
    paramsinghvc commented #1382
  • Sep 11 07:02
    paramsinghvc commented #1382
Saad Quadri
@saadq
whats up
delphi
@johndeguerto
koa is the so easy to use, I prefer it over express
reason this channel isn’t as active as express is because of it’s simplistic design and therefore not everyone requires help
delphi
@johndeguerto
Btw guys here is a slocket cluster koa base application with koa router. https://github.com/johndeguerto/SocketCluster-koa
Now you can run koa with all cpu power and all of socket cluster features
David Ojimba
@davidkayce_gitlab
hello everyone, nice to be here
I am a newbie to koa and I am trying to use it for an app using mongoose
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')
This keeps returning a 404 not found error
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.
Freddy
@fjeddy
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.
krg7880
@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?