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‘) } })
时间: 2024-10-12 01:20:17