1
我有要求在hapijs應用程序中設置自定義HTTP狀態消息。如何做到這一點?我的代碼是:hapijs自定義http狀態消息
'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}`);
});
當我通過捲曲這樣稱呼它: curl -v http://localhost:3000/
我看到一個自定義HTTP標頭abc=123
,但HTTP狀態消息仍然OK
,而不是預期的Hello world
。請幫忙。 謝謝。
拉請求合併到主分支 –
我更新了我的項目依賴文件'package.json',像這樣:''hapi「:」^ 16.5.2「',來自項目文件夾的「node_modules」,發出'npm i'命令,因此node_modules重載了正確的hapijs版本。但我仍然得到了響應:'HTTP/1.1 200 OK',而不是預期的'HTTP/1.1 200 Hello world' – lospejos