mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-20 23:40:38 +01:00
fix breadcrumbs and home /api route not loading
This commit is contained in:
@@ -40,7 +40,7 @@ categoriesController.list = function (req, res, next) {
|
|||||||
categories: categoryData,
|
categories: categoryData,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (req.path.startsWith('/api/categories') || req.path.startsWith('/categories')) {
|
if (req.originalUrl.startsWith(nconf.get('relative_path') + '/api/categories') || req.originalUrl.startsWith(nconf.get('relative_path') + '/categories')) {
|
||||||
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: data.title }]);
|
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: data.title }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ categoryController.get = function (req, res, callback) {
|
|||||||
return helpers.redirect(res, categoryData.link);
|
return helpers.redirect(res, categoryData.link);
|
||||||
}
|
}
|
||||||
|
|
||||||
buildBreadcrumbs(categoryData, next);
|
buildBreadcrumbs(req, categoryData, next);
|
||||||
},
|
},
|
||||||
function (categoryData, next) {
|
function (categoryData, next) {
|
||||||
if (!categoryData.children.length) {
|
if (!categoryData.children.length) {
|
||||||
@@ -148,7 +148,7 @@ categoryController.get = function (req, res, callback) {
|
|||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
function buildBreadcrumbs(categoryData, callback) {
|
function buildBreadcrumbs(req, categoryData, callback) {
|
||||||
var breadcrumbs = [
|
var breadcrumbs = [
|
||||||
{
|
{
|
||||||
text: categoryData.name,
|
text: categoryData.name,
|
||||||
@@ -160,7 +160,9 @@ function buildBreadcrumbs(categoryData, callback) {
|
|||||||
helpers.buildCategoryBreadcrumbs(categoryData.parentCid, next);
|
helpers.buildCategoryBreadcrumbs(categoryData.parentCid, next);
|
||||||
},
|
},
|
||||||
function (crumbs, next) {
|
function (crumbs, next) {
|
||||||
|
if (req.originalUrl.startsWith(nconf.get('relative_path') + '/api/category') || req.originalUrl.startsWith(nconf.get('relative_path') + '/category')) {
|
||||||
categoryData.breadcrumbs = crumbs.concat(breadcrumbs);
|
categoryData.breadcrumbs = crumbs.concat(breadcrumbs);
|
||||||
|
}
|
||||||
next(null, categoryData);
|
next(null, categoryData);
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ pubsub.on('config:update', configUpdated);
|
|||||||
configUpdated();
|
configUpdated();
|
||||||
|
|
||||||
module.exports = function (req, res, next) {
|
module.exports = function (req, res, next) {
|
||||||
if (req.path !== '/' && req.path !== '/api/') {
|
if (req.path !== '/' && req.path !== '/api/' && req.path !== '/api') {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ module.exports = function (req, res, next) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
req.url = req.path + route;
|
req.url = req.path + (!req.path.endsWith('/') ? '/' : '') + route;
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ popularController.get = function (req, res, next) {
|
|||||||
term: term,
|
term: term,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (req.path.startsWith('/api/popular') || req.path.startsWith('/popular')) {
|
if (req.originalUrl.startsWith(nconf.get('relative_path') + '/api/popular') || req.originalUrl.startsWith(nconf.get('relative_path') + '/popular')) {
|
||||||
var breadcrumbs = [{ text: termToBreadcrumb[term] }];
|
var breadcrumbs = [{ text: termToBreadcrumb[term] }];
|
||||||
|
|
||||||
if (req.params.term) {
|
if (req.params.term) {
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ recentController.get = function (req, res, next) {
|
|||||||
var pageCount = Math.max(1, Math.ceil(data.topicCount / settings.topicsPerPage));
|
var pageCount = Math.max(1, Math.ceil(data.topicCount / settings.topicsPerPage));
|
||||||
data.pagination = pagination.create(page, pageCount, req.query);
|
data.pagination = pagination.create(page, pageCount, req.query);
|
||||||
|
|
||||||
if (req.path.startsWith('/api/recent') || req.path.startsWith('/recent')) {
|
if (req.originalUrl.startsWith(nconf.get('relative_path') + '/api/recent') || req.originalUrl.startsWith(nconf.get('relative_path') + '/recent')) {
|
||||||
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[recent:title]]' }]);
|
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[recent:title]]' }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,7 @@ unreadController.get = function (req, res, next) {
|
|||||||
data.categories = results.watchedCategories.categories;
|
data.categories = results.watchedCategories.categories;
|
||||||
data.selectedCategory = results.watchedCategories.selectedCategory;
|
data.selectedCategory = results.watchedCategories.selectedCategory;
|
||||||
data.selectedCids = results.watchedCategories.selectedCids;
|
data.selectedCids = results.watchedCategories.selectedCids;
|
||||||
|
if (req.originalUrl.startsWith(nconf.get('relative_path') + '/api/unread') || req.originalUrl.startsWith(nconf.get('relative_path') + '/unread')) {
|
||||||
if (req.path.startsWith('/api/unread') || req.path.startsWith('/unread')) {
|
|
||||||
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[unread:title]]' }]);
|
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[unread:title]]' }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user