Skip to content

Node.js based forum software built for the modern web

small fix to redirect

barisusakli8d0c659f0856
diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js
index 85d8acd44b..6d0a172414 100644
--- a/src/middleware/middleware.js
+++ b/src/middleware/middleware.js
@@ -86,9 +86,9 @@ middleware.checkPostIndex = function(req, res, next) {
}
var postIndex = parseInt(req.params.post_index, 10);
if (postIndex > postCount) {
- return res.redirect('/topic/' + req.params.topic_id + '/' + req.params.slug + '/' + postCount);
- } else if (postIndex <= 1) {
- return res.redirect('/topic/' + req.params.topic_id + '/' + req.params.slug);
+ return res.locals.isAPI ? res.json(302, '/topic/' + req.params.topic_id + '/' + req.params.slug + '/' + postCount) : res.redirect('/topic/' + req.params.topic_id + '/' + req.params.slug + '/' + postCount);
+ } else if (postIndex < 1) {
+ return res.locals.isAPI ? res.json(302, '/topic/' + req.params.topic_id + '/' + req.params.slug) : res.redirect('/topic/' + req.params.topic_id + '/' + req.params.slug);
}
next();
});