koa笔记之ctx对象:
ctx里面包括(request,response,app,originalUrl,req,res)
ctx.request:
{ method: 'GET',
url: '/',
header:
{ host: 'localhost:3001',
connection: 'keep-alive',
'cache-control': 'max-age=0',
'upgrade-insecure-requests': '1',
'user-agent':
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36 Maxthon/5.2.7.5000', accept:
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
dnt: '1',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN' } }
ctx.response:
{ status: 200,
message: 'OK',
header:
[Object: null prototype] {
'content-type': 'text/plain; charset=utf-8',
'content-length': '11' },
body: 'hello world' }
ctx.app
{ subdomainOffset: 2, proxy: false, env: 'development' }
ctx.originalUrl
/:返回的是根路径