我有一个 fastify node.js 应用程序,我可以在它返回给调用浏览器 JS 之前看到一个承诺的文本结果。当该承诺返回给浏览器 JS 时,我只能从承诺文本中得到一个空字符串。我假设承诺没有被链接,这是一个没有其他内容的新承诺。如果这是正确的,我将如何访问内部承诺结果?
我已经在 fastify 应用程序的模块之间传递了 Promise,在任何时候都没有问题得到结果,我只是不明白我在这一点上做错了什么。这些是我在通话双方都尝试做的基础知识:
// node.js
fastify.get('/promise', async function(request, reply) {
var results = await someFunction(request)
console.log(await results.text()) // this displays results as XML
return results
})
// call to fastify app from browser JS
async function getPromise(params) {
var response = await fetch("http://localhost:3000/promise" + params, { mode: 'no-cors' })
console.log(await response.text()) // this is empty
}