request.query 不会打印 Fastify 中的查询(querystring)
我搜索了很长时间,但它只是不会打印查询,我不知道我应该做什么。我也是 Fastify 的新手。我还将请求发送到 127.0.0.1/?greeting=something
。
const opts = {
schema: {
querystring: {
type: 'object',
required: ['greeting'],
properties: {
greeting: {type: 'string'},
},
},
response: {
200: {
type: 'object',
properties: {
status: {type: 'object'}, // i've abosulutely no idea what the type should be
},
},
},
},
handler: async (request, reply) => {
reply.send({
status: request.query,
})
}
}
有人可以帮我解决这个问题吗?
I searched for ages, but it just wouldn't print the query, I've no idea what I should do. I'm also kind of new to Fastify. Also I'm sending the request to 127.0.0.1/?greeting=something
.
const opts = {
schema: {
querystring: {
type: 'object',
required: ['greeting'],
properties: {
greeting: {type: 'string'},
},
},
response: {
200: {
type: 'object',
properties: {
status: {type: 'object'}, // i've abosulutely no idea what the type should be
},
},
},
},
handler: async (request, reply) => {
reply.send({
status: request.query,
})
}
}
Can someone please help me in resolving this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于响应的架构,您看不到
request.query
输出。响应架构过滤掉所有未定义的字段,因此
properties
字段将status
键列为没有任何属性的对象。您应该将其更改为:
或添加
greetings
属性。您可以在这里阅读: https://github.com/fastify/fast-json -stringify#additionalProperties
You don't see the
request.query
output because of the response's schema.The response schema filters out all the fields that are not defined, so the
properties
field lists thestatus
key as object without any properties.You should change it to:
or adding the
greetings
property.You can read about it here: https://github.com/fastify/fast-json-stringify#additionalProperties