So I have an issue with Express.Js currently. When I goto /article/14
it returns with these as the parameter.
{ artId: '14' }
{ artId: 'img' }
However, I'm not sure where it gets the img
part from or how the value is there twice. However, if I go to a different Id article it works fine.
This is the full code
app.get('/article/:artId', async function (req, res) {
let artId = req.params.artId;
getDiscordUserInfo(req, res, function(disData) {
connection.query(`SELECT * FROM articles WHERE id = ${artId}`, (err, artResults) => {
if(artResults[0]) {
connection.query(`SELECT * FROM articles WHERE deleted = 0 AND catId = ${artResults[0].catId}`, (err, catArtsResults) => {
connection.query(`SELECT * FROM categories WHERE id = ${artResults[0].catId}`, (err, resultsCat) => {
res.render('article', {discordInfo: disData, siteInfo: config['siteInformation'], art: artResults[0], catArts: catArtsResults, cat: resultsCat[0], mdConvert: md});
});
});
} else {
res.redirect('/');
}
});
});
});
It also seems to still load the page and then crash because of img
.
Seems to be resolved. To make the articles I use a markdown converter and the image I placed in the body of the page seems to be the cause. I didn't have the link yet so I used img
as a placeholder in the code which made this the result;
Not sure how this in the body would be a cause but somehow was.
aha,,,
app.get('/article/:artId')
:artId is dynamic params. so if you have the same route maybe in your case
app.get('/article/:artId') // route 1
app.get('/article/img') // route 2
simple solution just add conditon before query to database
if(artId !== "img")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.