-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (31 loc) · 942 Bytes
/
server.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(function(){
"use strict";
const
Router = require('koa-router'),
koa = require('koa'),
app = koa();
//Middleware: request logger
function *reqlogger(next){
console.log('%s - %s %s',new Date().toISOString(), this.req.method, this.req.url);
yield next;
}
app.use(reqlogger);
app.use(Router(app));
app.get('/', function *(){
this.body = "This is root page ('/')";
});
function *account(){
this.body = "This is account page ('/account')";
}
app.get('/account', account);
const publicRouter = new Router();
publicRouter.get('/auth/github', function *(){
console.log("Middleware-style Example");
this.body = "Authenticate with GitHub OAUTH API (Coming Soon)";
});
app.use(publicRouter.middleware());
app.use(function *(){
this.body = 'Hello World';
});
app.listen(3000);
})();