【发布时间】:2020-04-16 02:28:20
【问题描述】:
我在Nodejs 中创建了一个API。我尝试创建一个返回 HTML 的调用以在浏览器中显示一个站点。
我的电话如下所示:
router.get('/displayHTML', checkAccessToken, (req, res, next) => {
if (req.query.data === undefined) {
return res.status(900).json({
message: 'Data does not exist'
});
}
Data.find({ data: req.query.data}).exec()
.then(data => {
if (data.length < 1) {
return res.status(400).json({
message: "Nothing found"
});
}
// I need to return HTML here so the user sees something in his browser
return res.status(200).json({
data: data
});
}).catch(error => {
return res.status(500).json({
message: error
});
});
});
【问题讨论】: