codecamp

Fastify Request(请求)

Request

处理函数的第一个参数是 Request.Request 是 Fastify 的核心对象,包含了一下的字段:

  • query - 解析后的 querystring
  • body - 消息主体
  • params - URL 参数
  • headers - headers
  • raw - Node 原生的 HTTP 请求 (可以用别名 req)
  • id - 请求 id
  • log - 请求的日志实例
  • ip - 请求方的 ip 地址
  • ips - x-forwarder-for header 中保存的请求源 ip 数组 (仅当 trustProxy 开启时有效)
  • hostname - 请求方的主机名
fastify.post('/:params', options, function (request, reply) {
  console.log(request.body)
  console.log(request.query)
  console.log(request.params)
  console.log(request.headers)
  console.log(request.raw)
  console.log(request.id)
  console.log(request.ip)
  console.log(request.ips)
  console.log(request.hostname)
  request.log.info('some info')
})


Fastify 回复
Fastify 错误处理
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }