When you use reply method:

let resp = reply(\'hello world\')

It actually return an response object.

 

By using response object, you can modiy the response\’s status code, header, cookie, type and so on…

server.route({
  method: \'GET\',
  path: \'/\',
  handler: function(request, reply) {
    let resp = reply(\'hello world\')
    resp.code(418) // set status code to 418
    resp.type(\'text/plain\') // set type to text/plain
    resp.header(\'hello\', \'world\') // set header to hello: world
    resp.state(\'hello\', \'world\') // set cookie to hello=world
  }

 

 response object is chainable:

server.route({
   method: \'GET\',
   path: \'/\',
   handler: function(req, reply){
      reply(\'hello world\')
        .code(418)
        .type(\'text/plain\')
        .header(\'hello\', \'world\')
       -state(\'hello\', \'world\')
   }   
})  

 

版权声明:本文为Answer1215原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/Answer1215/p/5225624.html?ivk_sa=1024320u