index.js
const Koa = require("koa");
const app = new Koa();
/**
* a simple log middleware
* @param {object} ctx
*/
function logger() {
return async function (ctx, next) {
console.log(ctx.method, ctx.header.host, ctx.url);
await next();
};
}
app.use(logger());
app.use((ctx) => {
ctx.body = "Hello, World!";
});
app.listen(3000);