rest.client 一直在等待

问题描述 投票:0回答:1

/
请求的处理程序是

module.exports = {  
  homepageHandler: async function (req, res) {
    console.log(`index page.`);
    return JSON.stringify({
      "message": "welcome"
    });
  }
}

app.js
-
app.get('/', indexControllerModule.homepageHandler); 

调用

我正在尝试使用

Rest Client
扩展来测试此端点。

Name: REST Client
Id: humao.rest-client
Description: REST Client for Visual Studio Code
Version: 0.25.1
Publisher: Huachao Mao
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=humao.rest-client

要求是

GET http://localhost:4000/
Content-Type: application/json

当我点击图片的

send request, the client seem to be stuck in 
等待`状态(见左下角)。

似乎从

console.log(`index page.`)
处理程序接收到请求(
index
的输出),但未收到响应。为什么?

我尝试使用

Promise.resolve
作为返回值,但这并没有解决问题。

return Promise.resolve(JSON.stringify({
      "message": "welcome"
    }));

express rest-client
1个回答
0
投票

我真傻!我没有从处理程序返回任何响应

已添加

res.status(200).send(body)

© www.soinside.com 2019 - 2024. All rights reserved.