欢迎来到阿八个人博客网站。本
阿八个人博客
网站提供最新的站长新闻,各种互联网资讯。
喜欢本站的朋友可以收藏本站,或者加QQ:我们大家一起来交流技术!
URL链接:https://www.abboke.com/jsh/2019/0702/4328.html
1190000019640621
const router = require('koa-router')()
router.get('/', async (ctx, next) => {
await ctx.render('index', {
title: 'Hello Koa 2!'
})
})
router.get('/string', async (ctx, next) => {
ctx.body = 'koa2 string'
})
router.get('/json', async (ctx, next) => {
// http://localhost:3000/json?name=lius&age=26&sex=true
ctx.body = {
url: ctx.url,
ctx_query: ctx.query,
ctx_querystring: ctx.querystring
}
// {
// "url": "/json?name=lius&age=26&sex=true",
// "ctx_query": {
// "name": "lius",
// "age": "26",
// "sex": "true"
// },
// "ctx_querystring": "name=lius&age=26&sex=true"
// }
})
router.post('/json',async (ctx,next)=>{
await ctx.cookies.set('name',ctx.request.body.name)
console.log('name',ctx.cookies.get('name'))
ctx.body = ctx.request.body
})
module.exports = router