【发布时间】:2021-02-01 05:47:38
【问题描述】:
这里最后一个 GET 请求方法是唯一不返回任何内容的方法。我控制台日志以查看是否正在执行某些操作,但甚至没有任何内容被记录到控制台。
router.get('/', function(req, res) {
Golf.find({Year: {$gte: 2021}, "Title": "Corales Puntacana Resort & Club Championship"})
.then(info => res.status(200).json(info))
.catch(err => res.status(404).json({msg: 'no scores found'}))
})
//Get data of each player in specific tournament
router.get('/:year/:tournament', function(req, res) {
let tourny = decodeURI(req.params.tournament)
let yearly = parseInt(req.params.year)
Golf.find({Year: yearly, "Title": tourny})
.then(info => res.status(200).json(info))
.catch(err => res.status(404).json({msg: 'no scores found'}))
})
//Get years
router.get('/getyears', function(req, res) {
Golf.find().distinct("Year")
.then(info => res.status(200).json(info))
.catch(err => res.status(404).json({msg: 'no years found'}))
})
//Get tournaments in a year
router.get('/:year', function(req, res) {
let yearly = parseInt(req.params.year)
Golf.find({Year: yearly}).distinct("Title")
.then(info => res.status(200).json(info))
.catch(err => res.status(404).json({msg: 'no years found'}))
})
//Get player names in a specific tournament
router.get('/player/:year/:tournament', function(req, res) {
let tourny = decodeURI(req.params.tournament)
let yearly = parseInt(req.params.year)
Golf.find({Year: yearly, "Title": tourny}).distinct("Name")
.then(info => res.status(200).json(info))
.catch(err => res.status(404).json({msg: 'no scores found'}))
})
//Get all player's performances in database
router.get('/:name', function(req, res) {
let person = decodeURI(req.params.name)
console.log(person)
Golf.find({"Name": person})
.then(info => res.status(200).json(info))
.catch(err => res.status(404).json({msg: 'no person found'}))
})
这是不起作用的GET请求方法。
//Get all player's performances in database
router.get('/:name', function(req, res) {
let person = decodeURI(req.params.name)
console.log(person)
Golf.find({"Name": person})
.then(info => res.status(200).json(info))
.catch(err => res.status(404).json({msg: 'no person found'}))
})
【问题讨论】:
标签: javascript reactjs express mongoose