//POST route - making user post a review under a gamerouter.post('/', (req, res) => {db.user.create({content: req.body.content,userId: req.body.userId}).then((post) => {res.redirect('/views/review')}).catch((error) => {res.status(400).render('main/404')})})// GET routerouter.get('/:id', (req, res) => {// res.send("You've reached the review route!")console.log(req.params.id)axios.get(https://api.rawg.io/api/${req.params.id}?key=${process.env.RAWG_API_KEY}).then(apiRes => {console.log('this is apiRes', apiRes.data)const gameData = apiRes.data.resultsres.render('review.ejs')})}).catch((error) => {res.status(400).render('main/404')})
### If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
When I try to go into the review page directly by typing /review:
`ReferenceError: /mnt/c/Users/juanr/sei_pumpkin_smashers/project-2-Game-Review/views/review.ejs:16`
`14| <h4>Comments</h4>`
`15| <ul>`
`>> 16| <% gameData.forEach((game)=>{ %>`
`17| <li>`
`18| <a href="<%= game.background_id %>">`
`19| <%= game.name %> </a>`
`gameData is not defined`
`at eval (eval at compile (/mnt/c/Users/juanr/sei_pumpkin_smashers/project-2-Game-Review/node_modules/ejs/lib/ejs.js:662:12),` `<anonymous>:12:8)`
`at review (/mnt/c/Users/juanr/sei_pumpkin_smashers/project-2-Game-Review/node_modules/ejs/lib/ejs.js:692:17)`
`at tryHandleCache (/mnt/c/Users/juanr/sei_pumpkin_smashers/project-2-Game-Review/node_modules/ejs/lib/ejs.js:272:36)`
`at View.exports.renderFile [as engine] (/mnt/c/Users/juanr/sei_pumpkin_smashers/project-2-Game-``Review/node_modules/ejs/lib/ejs.js:489:10)`
`at View.render (/mnt/c/Users/juanr/sei_pumpkin_smashers/project-2-Game-Review/node_modules/express/lib/view.js:135:8)`
`at tryRender (/mnt/c/Users/juanr/sei_pumpkin_smashers/project-2-Game-Review/node_modules/express/lib/application.js:640:10)`
`at Function.render (/mnt/c/Users/juanr/sei_pumpkin_smashers/project-2-Game-`Review/node_modules/express/lib/application.js:592:3)
`at ServerResponse.render (/mnt/c/Users/juanr/sei_pumpkin_smashers/project-2-Game-`Review/node_modules/express/lib/response.js:1017:7)
`at ServerResponse.res.render (/mnt/c/Users/juanr/sei_pumpkin_smashers/project-2-Game-Review/node_modules/express-ejs-layouts/lib/express-layouts.js:77:18)`
`at axios.get.then.apiRes (/mnt/c/Users/juanr/sei_pumpkin_smashers/project-2-Game-Review/index.js:66:13)`
When I try to get redirected by clicking the game:
`Cannot GET /review/Grand%20Theft%20Auto%20V`
### What is your best guess as to the source of the problem?
### What things have you already tried to solve the problem?
I tried putting the API into the controller GET route but nothing happened
What stack are you using?
(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)
Express, Postgres, Psql, Nodejs
What's the problem you're trying to solve?
When click on a game title from my home page to redirect me to the review page I get a 'gameData is not defined' error
Post any code you think might be relevant (one fenced block per file)
``const { render } = require("ejs");
const db = require("../models");
const router = require("./igdb");
//POST route - making user post a review under a game
router.post('/', (req, res) => {
db.user.create({
content: req.body.content,
userId: req.body.userId
})
.then((post) => {
res.redirect('/views/review')
})
.catch((error) => {
res.status(400).render('main/404')
})
})
// GET route
router.get('/:id', (req, res) => {
// res.send("You've reached the review route!")
console.log(req.params.id)
axios.get(
https://api.rawg.io/api/${req.params.id}?key=${process.env.RAWG_API_KEY})
.then(apiRes => {
console.log('this is apiRes', apiRes.data)
const gameData = apiRes.data.results
res.render('review.ejs')
})
})
.catch((error) => {
res.status(400).render('main/404')
})