Koa

Koa 是一個新的 web 框架,由 Express 幕後的原班人馬打造, 致力於成爲 web 應用和 API 開發領域中的一個更小、更富有表現力、更健壯的基石。express的進階版。web

  const Koa = require('koa');express

   const app = new Koa(); app

  app.use(async ctx => { ctx.body = 'Hello World'; }); 框架

  app.listen(3000);koa

 

  const Koa = require('koa');async

  const app = new Koa(); ui

  logger app.use(async (ctx, next) => { await next(); const rt = ctx.response.get('X-Response-Time');url

   console.log(`${ctx.method} ${ctx.url} - ${rt}`); });     code

  x-response-time app.use(async (ctx, next) => { const start = Date.now(); await next(); 開發

  const ms = Date.now() - start; ctx.set('X-Response-Time', `${ms}ms`); }); 

  response app.use(async ctx => { ctx.body = 'Hello World'; }); app.listen(3000);

相關文章
相關標籤/搜索