Next.js: Ejemplo Koa2

Creado en 27 feb. 2017  ·  3Comentarios  ·  Fuente: vercel/next.js

¿Alguien tiene un ejemplo simple usando Koa 2?

example

Comentario más útil

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)
})

Todos 3 comentarios

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)
})

@timneutkens como Node ahora tiene async/await, Koa 2.0.1 se lanzó hace 3 días 😄 Supongo que tendría sentido actualizar el ejemplo para usar esta versión.

Cierto, voy a crear un nuevo ticket.

¿Fue útil esta página
0 / 5 - 0 calificaciones