Koa 是一个新的 web 框架,由 Express 幕后的原班人马打造, 致力于成为 web 应用和 API 开发领域中的一个更小、更富有表现力、更健壮的基石。express的进阶版。
const Koa = require('koa');
const app = new Koa();
app.use(async ctx => { ctx.body = 'Hello World'; });
app.listen(3000);
const Koa = require('koa');
const app = new Koa();
logger app.use(async (ctx, next) => { await next(); const rt = ctx.response.get('X-Response-Time');
console.log(`${ctx.method} ${ctx.url} - ${rt}`); });
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);