forked from koajs/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (24 loc) · 610 Bytes
/
app.js
File metadata and controls
30 lines (24 loc) · 610 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var koa = require('koa');
var app = module.exports = koa();
app.use(function *pageNotFound(next){
yield next;
if (404 != this.status) return;
// we need to explicitly set 404 here
// so that koa doesn't assign 200 on body=
this.status = 404;
switch (this.accepts('html', 'json')) {
case 'html':
this.type = 'html';
this.body = '<p>Page Not Found</p>';
break;
case 'json':
this.body = {
message: 'Page Not Found'
};
break
default:
this.type = 'text';
this.body = 'Page Not Found';
}
})
if (!module.parent) app.listen(3000);