Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create migration docs from Koa 1.x to 2.x #621

Closed
pensierinmusica opened this issue Dec 13, 2015 · 6 comments
Closed

Create migration docs from Koa 1.x to 2.x #621

pensierinmusica opened this issue Dec 13, 2015 · 6 comments

Comments

@pensierinmusica
Copy link

Refers to #523 (comment)

Are there any docs about:

  • What is being changed from 1.x to 2.x, why, and what is the performance difference
  • How 2.x works
  • What are best practices to convert from 1.x to 2.x
  • What modules support 2.x

Also, @tj how reliable is Koa 2.0.0-alpha.3 to be used in production?

Thanks!

@alqu
Copy link

alqu commented Dec 16, 2015

@pensierinmusica I am using Koa 2.0.0-alpha.3 since a couple of weeks now.
It is pretty stable. I use it in a "near production" environment and plan to release the final version in 1 month.

No problems so far. I had to write a little module for basic auth (well, 10loc only), a modified logger with winston and my own error handler and that's it.
The rest - mongoose, koa-bodyparser@3.0.0, koa-router@7.0.0 and koa-serve-static work nicely together with koa 2.0

Just my 2 cents.

@pensierinmusica
Copy link
Author

@alqu thanks for the feedback!

I had to write a little module for basic auth (well, 10loc only), a modified logger with winston and my own error handler and that's it.

Does Koa 2.x still provide this default error handler?

app.on('error', function(err){
  log.error('server error', err);
});

Cheers!

@alqu
Copy link

alqu commented Dec 16, 2015

well, it looks a bit different:

app.on('error', function (err, ctx) {
  if (err == null) return

  if (!(err instanceof Error)) err = new Error(`non-error thrown: ${err}`)

  if (ctx) {
    // do some stuff here.
    let msg = {} // whatever you want to respond with
    // finally, make sure you finish properly:
    msg = JSON.stringify(msg)
    ctx.res.statusCode = err.status
    ctx.res.length = Buffer.byteLength(msg)
    ctx.res.end(msg)
  }
})

@alqu
Copy link

alqu commented Dec 16, 2015

But... yeah, you could write the one you suggested. But you should also react on errors...

@pensierinmusica
Copy link
Author

@alqu of course ;) That was just copy / paste from Koajs official docs, what I wondered is if the 'error' event handler was still there in Koa 2.x, which you confirm. Great!

@jonathanong
Copy link
Member

i updated the description here: #533 (comment)

closing this issue - any future comments should go in that thread :)

@koajs koajs locked and limited conversation to collaborators Jan 18, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants