【发布时间】:2023-03-17 23:05:02
【问题描述】:
我目前正在使用 hapi,但我遇到了一个我似乎无法找到任何解决方案或之前提到过的问题。当我发送以下请求时,只有我的第一个查询参数在 request.query 对象中。
curl -H "Content-Type: application/json" -X PUT https://localhost:3000/lists/{username}/{listname}?token='token'&resource_id='resource_id'
将{} 和'' 中的项目替换为实际名称。
我的路线目前是这样写的
server.route({
method: 'PUT',
path: '/lists/{username}/{listname}',
handler: function(request, reply) {
const username = encodeURIComponent(request.params.username);
const listname = encodeURIComponent(request.params.listname);
const resource_id = request.query.resource_id;
const token = request.query.token;
console.log(request.query);
verify(token, username, {callback}, listname, resource_id, reply);
}
});
console.log 调用导致
{ token: 'token' }
如果我执行console.log(resource_id),我会在控制台中得到“未定义”。 hapi 的文档指出所有查询参数都应该在request.query 对象中找到。由于某种原因,这没有发生。我查看了 hapijs 文档,查看了我的 API 调用,并阅读了人们处理查询参数的示例。知道这里发生了什么吗?
【问题讨论】:
标签: javascript node.js https hapijs query-parameters