-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
21 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
var router = require('koa-router')(); | ||
|
||
router.get('/', async function (ctx, next) { | ||
ctx.state = { | ||
title: 'koa2 title' | ||
}; | ||
const router = require('koa-router')() | ||
|
||
router.get('/', async (ctx, next) => { | ||
await ctx.render('index', { | ||
}); | ||
title: 'Hello Koa 2!' | ||
}) | ||
}) | ||
|
||
router.get('/foo', async function (ctx, next) { | ||
await ctx.render('index', { | ||
title: 'koa2 foo' | ||
}); | ||
}); | ||
router.get('/string', async (ctx, next) => { | ||
ctx.body = 'koa2 string' | ||
}) | ||
|
||
router.get('/json', async (ctx, next) => { | ||
ctx.body = { | ||
title: 'koa2 json' | ||
} | ||
}) | ||
|
||
module.exports = router; | ||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
var router = require('koa-router')(); | ||
const router = require('koa-router')() | ||
|
||
router.prefix('/users'); | ||
router.prefix('/users') | ||
|
||
router.get('/', function (ctx, next) { | ||
ctx.body = 'this is a users response!'; | ||
}); | ||
ctx.body = 'this is a users response!' | ||
}) | ||
|
||
router.get('/bar', function (ctx, next) { | ||
ctx.body = 'this is a users/bar response'; | ||
}); | ||
ctx.body = 'this is a users/bar response' | ||
}) | ||
|
||
module.exports = router; | ||
module.exports = router |