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

Example Koa2 #1303

Closed
mistakenelf opened this issue Feb 27, 2017 · 3 comments
Closed

Example Koa2 #1303

mistakenelf opened this issue Feb 27, 2017 · 3 comments
Labels
examples Issue/PR related to examples

Comments

@mistakenelf
Copy link

Anyone have a simple example using Koa 2?

@timneutkens timneutkens added the examples Issue/PR related to examples label Feb 27, 2017
@cncolder
Copy link
Contributor

cncolder commented Feb 28, 2017

const n = next({ dev })
const handle = n.getRequestHandler()

n.prepare()
.then(() => {
  const app = new Koa()
  const router = new Router()

  router.get('*', async ctx => {
    await handle(ctx.req, ctx.res)
    ctx.respond = false
  })

  app.use(async (ctx, next) => {
    // Koa doesn't seems to set the default statusCode.
    // So, this middleware does that
    ctx.res.statusCode = 200
    await next()
  })

  app.use(router.routes())

  app.listen(3000)
})

@sedubois
Copy link
Contributor

@timneutkens as Node now has async/await, Koa 2.0.1 was just released 3 days ago 😄 I guess it would make sense to update the example to use this version.

@timneutkens
Copy link
Member

True, I'll create a new ticket.

@lock lock bot locked as resolved and limited conversation to collaborators May 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
examples Issue/PR related to examples
Projects
None yet
Development

No branches or pull requests

4 participants