dongyu 50bcadf73e migrate to koa@2 (#108)
* support async/await

* change nodejs version 4 or 6 to 5.6

* eslint

* remove jade
2017-05-30 20:44:57 +08:00

33 lines
769 B
JavaScript

const logger = require('koa-logger');
const Koa = require('koa');
const app = new Koa();
// passing any middleware to this middleware
// will make it conditional, and will not be used
// when an asset is requested, illustrating how
// middleware may "wrap" other middleware.
function ignoreAssets(mw) {
return async function(ctx, next) {
if (/(\.js|\.css|\.ico)$/.test(ctx.path)) {
await next();
} else {
// must .call() to explicitly set the receiver
await mw.call(this, ctx, next);
}
};
}
// TRY:
// $ curl http://localhost:3000/
// $ curl http://localhost:3000/style.css
// $ curl http://localhost:3000/some.html
app.use(ignoreAssets(logger()));
app.use(async function(ctx) {
ctx.body = 'Hello World';
});
app.listen(3000);