The handler for /
request is
/请求的处理程序是
module.exports = {
homepageHandler: async function (req, res) {
console.log(`index page.`);
return JSON.stringify({
"message": "welcome"
});
}
}
It is called from app.js
- app.get('/', indexControllerModule.homepageHandler);
从app.js-app.get(‘/’,indexControllerModule.home epageHandler)调用;
I am trying to test this endpoint using Rest Client
extension.
我正在尝试使用REST客户端扩展来测试这个端点。
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
The request is
我的要求是
GET http://localhost:4000/
Content-Type: application/json
When I click on send request, the client seem to be stuck in
waiting` state (see lower left corner) of the pic.
当我点击发送请求时,客户端似乎停留在图片的等待状态(见左下角)。
Seem the request is received (output of console.log(`index page.`)
) from index
handler but the response isn't received. Why?
似乎收到了来自索引处理程序的请求(console.log(`index page.`)的输出),但没有收到响应。为什么?
I tried using Promise.resolve
for return value but that didn't solve the issue.
我尝试使用Promise.Resolve作为返回值,但没有解决问题。
return Promise.resolve(JSON.stringify({
"message": "welcome"
}));
更多回答
优秀答案推荐
silly me! I didn't return any response from the handler
我真傻!我没有从处理程序返回任何响应
added res.status(200).send(body)
已添加Res.Status(200)。发送(正文)
更多回答
我是一名优秀的程序员,十分优秀!