Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 28 15:26

    dependabot[bot] on npm_and_yarn

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

  • Sep 28 15:26

    dependabot[bot] on npm_and_yarn

    (compare)

  • Sep 28 15:26
    dependabot[bot] commented #1690
  • Sep 28 15:26
    dependabot[bot] closed #1690
  • Sep 28 15:26
    dependabot[bot] labeled #1692
  • Sep 28 15:26
    dependabot[bot] opened #1692
  • Sep 26 14:45
    mylastore commented #689
  • Sep 21 12:03
    sjfkai edited #1691
  • Sep 21 12:03
    sjfkai edited #1691
  • Sep 21 12:03
    sjfkai edited #1691
  • Sep 21 12:02
    sjfkai labeled #1691
  • Sep 21 12:02
    sjfkai opened #1691
  • Sep 13 11:18
    miwnwski unlabeled #1682
  • Sep 13 11:17
    miwnwski closed #1682
  • Sep 13 11:17
    miwnwski labeled #1684
  • Sep 13 11:17
    miwnwski labeled #1684
  • Sep 13 11:17
    miwnwski commented #1684
  • Sep 13 11:16
    miwnwski commented #1683
  • Sep 13 11:06
    iwanofski commented #1688
  • Sep 12 15:25
    dependabot[bot] closed #1689
Jack c
@soydepr
@saadq i see thanks
Ghost
@ghost~5bb3c7fed73408ce4faa2518

I recently developed a framework is Hyron, which helps to save more backend application development time. Serving for large and complex project development, with high expansion needs. Looking forward to receiving suggestions from everyone
https://docs.hyron.org/

demo.js

module.exports = class {
    static requestConfig(){
        return {
            sayHello : "get"
        }
    }

    sayHello(name){
        return "hello world !"+name;
    }
}

app.json

{
    "base_url" : "http://localhost:3000",
    "services" : {
        "demo" : "./demo.js"
    }
}

bash

$ hyron start

result

> GET http://localhost:3000/demo/say-hello?name=arg

_

Eyal Perry
@_eyalPerry_twitter

I have a koa newcommer question, which might sound silly :)
does a koa middleware have to call await next()?

i.e.:
https://gist.github.com/EyalPerry/6fab361cfd6fdf704e7cd5a43c0ede7e

Jame
@jamemackson
@_eyalPerry_twitter your middleware doesn’t HAVE to call that, but if you want to do something on the way back up the middleware stack, you’ll want to call that and put the “after” logic after the await next();
Naguib Ihab (A.K.A. Nick)
@naguibIhab_twitter
hey guys, I'm still discovering KOA, what does the .middleware() here do?
export default new Router<ApplicationState, ApplicationContext>()
  .get('/', (ctx) => (ctx.body = ctx.greeting.getGreeting()))
  .middleware();
Saad Quadri
@saadq
Is that koa-router or some other router library?
Haven't seen a middleware() method on it before

Hmm... I see. The middleware() method isn't mentioned in the API docs: https://github.com/ZijianHe/koa-router#api-reference

But it does exist in the TypeScript definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/koa-router/index.d.ts#L461

@naguibIhab_twitter Ah found it: https://github.com/ZijianHe/koa-router/blob/master/lib/router.js#L314

It looks like .middleware() is just the same exact thing as the .routes() method

Saad Quadri
@saadq

And .routes() basically just returns a middleware that you use with your main Koa app like:

app.use(router.routes())

which would be the same as

app.use(router.middleware())
Naguib Ihab (A.K.A. Nick)
@naguibIhab_twitter
gotcha thanks @saadq
Naguib Ihab (A.K.A. Nick)
@naguibIhab_twitter
delphi
@johndeguerto
is it possible to access the koa.context.object inside a passportjs plementation?
Muhammad Habib
@habibsatti_twitter
hi
Saad Quadri
@saadq
hey :D
Marco Carvalho
@mcarvalho21
hi all
Marco Carvalho
@mcarvalho21
anyone alive?
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?