examples/404/app.js
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

27 lines
569 B
JavaScript

const Koa = require('koa');
const app = module.exports = new Koa();
app.use(async function pageNotFound(ctx) {
// we need to explicitly set 404 here
// so that koa doesn't assign 200 on body=
ctx.status = 404;
switch (ctx.accepts('html', 'json')) {
case 'html':
ctx.type = 'html';
ctx.body = '<p>Page Not Found</p>';
break;
case 'json':
ctx.body = {
message: 'Page Not Found'
};
break;
default:
ctx.type = 'text';
ctx.body = 'Page Not Found';
}
});
if (!module.parent) app.listen(3000);