Next.js: Beispiel Koa2

Erstellt am 27. Feb. 2017  ·  3Kommentare  ·  Quelle: vercel/next.js

Hat jemand ein einfaches Beispiel mit Koa 2?

example

Hilfreichster Kommentar

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

Alle 3 Kommentare

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 , da Node jetzt async/await hat, Koa 2.0.1 wurde erst vor 3 Tagen veröffentlicht 😄 Ich denke, es wäre sinnvoll, das Beispiel zu aktualisieren, um diese Version zu verwenden.

Richtig, ich erstelle ein neues Ticket.

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen