Skip to content

Node.js based forum software built for the modern web

closes #1422

barisusakli1d1d677b56a2
diff --git a/src/controllers/topics.js b/src/controllers/topics.js
index 19fa9e66a9..d36f96a6e8 100644
--- a/src/controllers/topics.js
+++ b/src/controllers/topics.js
@@ -9,6 +9,7 @@ var topicsController = {},
user = require('./../user'),
meta = require('./../meta'),
topics = require('./../topics'),
+ posts = require('../posts'),
threadTools = require('./../threadTools'),
utils = require('./../../public/src/utils');
@@ -181,4 +182,29 @@ topicsController.get = function(req, res, next) {
});
};
+topicsController.teaser = function(req, res, next) {
+ var tid = req.params.topic_id;
+ topics.getLatestUndeletedPid(tid, function(err, pid) {
+ if (err) {
+ return next(err);
+ }
+
+ if (!pid) {
+ return res.json(404, 'not-found');
+ }
+
+ posts.getPostSummaryByPids([pid], false, function(err, posts) {
+ if (err) {
+ return next(err);
+ }
+
+ if (!Array.isArray(posts) || !posts.length) {
+ return res.json(404, 'not-found');
+ }
+
+ res.json(posts[0]);
+ });
+ });
+};
+
module.exports = topicsController;
diff --git a/src/routes/index.js b/src/routes/index.js
index aef5c28b37..a0ab63a769 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -49,6 +49,8 @@ function staticRoutes(app, middleware, controllers) {
}
function topicRoutes(app, middleware, controllers) {
+ app.get('/api/topic/teaser/:topic_id', controllers.topics.teaser);
+
app.get('/topic/:topic_id/:slug?', middleware.buildHeader, middleware.addSlug, controllers.topics.get);
app.get('/api/topic/:topic_id/:slug?', controllers.topics.get);
}