javascript - hapijs custom http status message -
i have requirement set custom http status message in hapijs application. how done? code is:
'use strict'; const hapi = require('hapi'); const server = new hapi.server(); server.connection({ port: 3000, host: 'localhost' }); server.route({ method: 'get', path: '/', handler: function (request, reply) { reply('hello, world!\n') .header('set-cookie', 'abc=123') .message("hello world"); } }); server.start((err) => { if (err) { throw err; } console.log(`server running at: ${server.info.uri}`); }); when call via curl this: curl -v http://localhost:3000/ see custom http header abc=123, http status message still ok instead of expected hello world. please help. thanks.
it bug , there's open pull request fix it. can confirm able reproduce problem hapi 16.5 (from master) , works should after applying pull request.
if need right , can't wait pull request accepted can follow steps took test it:
$ rm -r node_modules/hapi $ git clone https://github.com/hapijs/hapi.git node_modules/hapi then edit node_modules/hapi/.git/config [remote "origin"] block follows:
[remote "origin"] url = https://github.com/hapijs/hapi.git fetch = +refs/heads/*:refs/remotes/origin/* fetch = +refs/pull/*/head:refs/remotes/origin/pr/* (add third line)
$ cd node_modules/hapi $ git fetch origin $ git checkout pr/3560 // optional if don't want nested git repo in project $ rm -r .git and custom status message should work :)
Comments
Post a Comment