【发布时间】:2017-08-04 04:22:21
【问题描述】:
我需要在 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 调用它时:
curl -v http://localhost:3000/ 我看到一个自定义 http 标头 abc=123,但 http 状态消息仍然是 OK 而不是预期的 Hello world。请帮忙。
谢谢。
【问题讨论】:
标签: javascript node.js hapijs