ga-wdi-exercises/project4

Can`t aceess show page json

Closed this issue · 14 comments

I can get index page JSON data but not show page.
Here is part of my code:

// My catagoryController
show(req,res){
    Person.findOne({name: req.params.name},(err,contact)=>{
      console.log(contact);
      res.send(contact)
    })
  }
//index.js
app.get('/backend/:catagory', catagoryController.show)

screenshot

Does your program ever console.log the value of contact

Yes when I run my controller, it does. I can see the result in the terminal(not the browser).

since you have {name: req.params.name} as your 1st argument to .findOne():
Change

app.get('/backend/:catagory', catagoryController.show)`

to

app.get('/backend/:name', catagoryController.show)

I did it, but still no change.

What's the value of contact when it is logged?

If I run the controller and put this code:
catagoriesController.show({catagoryName: "aaa"})
Then the log show me detail about aaa

You have data in your mongo db, right?

The previous image is screenshot when I use postman.
Here is screenshot of browser
screenshot2

Yes I have data I can see index page clearly.

Ah that's what I thought, badcfg refers to when an object is received instead of an array (single thing instead of a list of things). Instead of .query(), use .get().

ops now even I can`t see index page

I don't have a sense of where you are with your issue, can you include relevant code and errors?

now solved, thanks.

yay!