Next.js: مثال Koa2

تم إنشاؤها على ٢٧ فبراير ٢٠١٧  ·  3تعليقات  ·  مصدر: vercel/next.js

أي شخص لديه مثال بسيط باستخدام Koa 2؟

example

التعليق الأكثر فائدة

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

ال 3 كومينتر

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 حيث أصبح Node الآن غير متزامن / انتظار ، تم إصدار Koa 2.0.1 منذ 3 أيام فقط 😄 أعتقد أنه سيكون من المنطقي تحديث المثال لاستخدام هذا الإصدار.

صحيح ، سأقوم بإنشاء تذكرة جديدة.

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات