【问题标题】:Cannot GET error with node back end节点后端无法获取错误
【发布时间】:2018-06-07 20:36:00
【问题描述】:

我正在为我的服务器的后端编码我不知道为什么我的代码给了我一个错误。这是我下面的代码。

//@routes Get api/profiles/handle/:handle
//@desc Get frofile by handle
//@access public

router.get('/handle/:handle', (req, res) => {
  const error = { };
  Profile.findOne({handle : req.param.handle})
  .populate('user', ['name', 'avatar'])
  .then(profile => {
    if(!profile){
      errors.noprofile= "There is no profile for this user";
      res.status(404).json(errors)
    }

    res.json(profile);
  })
  .catch(err => res.status(404).json(err))
}); 

这是我使用邮递员获取的网址。

http://localhost:5000/api/profiles/handle/sambulo

我得到下面的错误我不知道出了什么问题。

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Error</title>
    </head>
    <body>
        <pre>Cannot GET /api/profiles/handle/sambulo</pre>
    </body>
</html>

【问题讨论】:

  • 尝试使用完整路由 api/profiles/handle/:handle 而不是 /handle/:handle

标签: javascript node.js reactjs express


【解决方案1】:

你的路由有错误。

试试这个代码:

router.get('/api/profiles/handle/:handle', (req, res) => {
    // Your code here
}

【讨论】:

    猜你喜欢
    • 2020-12-19
    • 1970-01-01
    • 2014-01-21
    • 2017-05-18
    • 1970-01-01
    • 1970-01-01
    • 2015-08-03
    • 2020-12-23
    • 1970-01-01
    相关资源
    最近更新 更多