My node app is set up with two handlers, one for requests to the root URL and another for the slug. However, when I visit the root or slug URLs, the app crashes and I receive this error:
url is pointing to root
url has a slug
throw err; // Rethrow non-MySQL errors
I'm not sure what I did wrong. Here's my code:
app.get(
'/:slug',
(req, res) => {
connection.query(`select * from blogs where slug="${slug}"`,
(error, results) => {
if (error) console.log(error);
console.log('url has a slug');
res.render(
'somepage',
results
)
}
)
}
)
app.get(
'/',
(req, res) => {
connection.query(`select * from blogs`,
(error, results) => {
if (error) console.log(error);
console.log('url is pointing to root');
res.render(
'index',
{
title: 'Home page',
blogs: results
}
)
}
)
}
)