Skip to content

Node.js based forum software built for the modern web

closes #2231; see #2218

psychobunny1b2ccda40bef
diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js
index 9e49dfc3ee..4b347e0de1 100644
--- a/src/controllers/accounts.js
+++ b/src/controllers/accounts.js
@@ -24,7 +24,7 @@ var fs = require('fs'),
function userNotFound(res) {
if (res.locals.isAPI) {
- res.json(404, 'user-not-found');
+ res.status(404).json('user-not-found');
} else {
res.render('404', {
error: 'User not found!'
@@ -34,7 +34,7 @@ function userNotFound(res) {
function userNotAllowed(res) {
if (res.locals.isAPI) {
- res.json(403, 'not-allowed');
+ res.status(403).json('not-allowed');
} else {
res.render('403', {
error: 'Not allowed.'
diff --git a/src/controllers/api.js b/src/controllers/api.js
index a43678d22a..baa07ffe82 100644
--- a/src/controllers/api.js
+++ b/src/controllers/api.js
@@ -54,7 +54,7 @@ apiController.getConfig = function(req, res, next) {
if (!req.user) {
if (res.locals.isAPI) {
- res.json(200, config);
+ res.status(200).json(config);
} else {
next(null, config);
}
@@ -75,7 +75,7 @@ apiController.getConfig = function(req, res, next) {
config.topicPostSort = settings.topicPostSort || config.topicPostSort;
if (res.locals.isAPI) {
- res.json(200, config);
+ res.status(200).json(config);
} else {
next(err, config);
}
@@ -95,7 +95,7 @@ apiController.renderWidgets = function(req, res, next) {
renderedWidgets = [];
if (!areas.template || !areas.locations) {
- return res.json(200, {});
+ return res.status(200).json({});
}
widgets.render(uid, {
@@ -106,7 +106,7 @@ apiController.renderWidgets = function(req, res, next) {
if (err) {
return next(err);
}
- res.json(200, widgets);
+ res.status(200).json(widgets);
});
};
diff --git a/src/controllers/categories.js b/src/controllers/categories.js
index d62bf385b9..23060f7a0f 100644
--- a/src/controllers/categories.js
+++ b/src/controllers/categories.js
@@ -227,17 +227,17 @@ categoriesController.get = function(req, res, next) {
};
categoriesController.notFound = function(req, res) {
- res.locals.isAPI ? res.json(404, 'not-found') : res.status(404).render('404');
+ res.locals.isAPI ? res.status(404).json('not-found') : res.status(404).render('404');
};
categoriesController.notAllowed = function(req, res) {
var uid = req.user ? req.user.uid : 0;
if (uid) {
- res.locals.isAPI ? res.json(403, 'not-allowed') : res.status(403).render('403');
+ res.locals.isAPI ? res.status(403).json('not-allowed') : res.status(403).render('403');
} else {
if (res.locals.isAPI) {
req.session.returnTo = apiToRegular(req.url);
- res.json(401, 'not-authorized');
+ res.status(401).json('not-authorized');
} else {
req.session.returnTo = req.url;
res.redirect(nconf.get('relative_path') + '/login');
diff --git a/src/controllers/topics.js b/src/controllers/topics.js
index aae961e20f..01246b8adc 100644
--- a/src/controllers/topics.js
+++ b/src/controllers/topics.js
@@ -49,10 +49,10 @@ topicsController.get = function(req, res, next) {
var url = '';
if (req.params.post_index > postCount) {
url = '/topic/' + req.params.topic_id + '/' + req.params.slug + '/' + postCount;
- return res.locals.isAPI ? res.json(302, url) : res.redirect(url);
+ return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url);
} else if (req.params.post_index < 1) {
url = '/topic/' + req.params.topic_id + '/' + req.params.slug;
- return res.locals.isAPI ? res.json(302, url) : res.redirect(url);
+ return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url);
}
}
@@ -275,7 +275,7 @@ topicsController.teaser = function(req, res, next) {
}
if (!canRead) {
- return res.json(403, '[[error:no-priveges]]');
+ return res.status(403).json('[[error:no-priveges]]');
}
topics.getLatestUndeletedPid(tid, function(err, pid) {
@@ -284,7 +284,7 @@ topicsController.teaser = function(req, res, next) {
}
if (!pid) {
- return res.json(404, 'not-found');
+ return res.status(404).json('not-found');
}
posts.getPostSummaryByPids([pid], uid, {stripTags: false}, function(err, posts) {
@@ -293,7 +293,7 @@ topicsController.teaser = function(req, res, next) {
}
if (!Array.isArray(posts) || !posts.length) {
- return res.json(404, 'not-found');
+ return res.status(404).json('not-found');
}
res.json(posts[0]);
diff --git a/src/middleware/admin.js b/src/middleware/admin.js
index 0f7af52358..0080a89cad 100644
--- a/src/middleware/admin.js
+++ b/src/middleware/admin.js
@@ -16,7 +16,7 @@ var app,
middleware.isAdmin = function(req, res, next) {
if (!req.user) {
- return res.json(404, {
+ return res.status(404).json({
error: 'not-found'
});
}
diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js
index ee24f032ae..53ba1eb5ff 100644
--- a/src/middleware/middleware.js
+++ b/src/middleware/middleware.js
@@ -27,7 +27,7 @@ var app,
middleware.authenticate = function(req, res, next) {
if(!req.user) {
if (res.locals.isAPI) {
- return res.json(403, 'not-allowed');
+ return res.status(403).json('not-allowed');
} else {
return res.redirect(nconf.get('url') + '/403');
}
@@ -68,7 +68,7 @@ middleware.redirectToAccountIfLoggedIn = function(req, res, next) {
}
if (res.locals.isAPI) {
- res.json(302, '/user/' + userslug);
+ res.status(302).json('/user/' + userslug);
} else {
res.redirect('/user/' + userslug);
}
@@ -91,7 +91,7 @@ middleware.addSlug = function(req, res, next) {
return next(err);
}
var url = name + encodeURI(slug);
- res.locals.isAPI ? res.json(302, url) : res.redirect(url);
+ res.locals.isAPI ? res.status(302).json(url) : res.redirect(url);
});
}
@@ -119,10 +119,10 @@ middleware.checkTopicIndex = function(req, res, next) {
if (topicIndex > topicCount) {
url = '/category/' + req.params.category_id + '/' + req.params.slug + '/' + topicCount;
- return res.locals.isAPI ? res.json(302, url) : res.redirect(url);
+ return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url);
} else if (topicIndex < 1) {
url = '/category/' + req.params.category_id + '/' + req.params.slug;
- return res.locals.isAPI ? res.json(302, url) : res.redirect(url);
+ return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url);
}
next();
});
@@ -146,7 +146,7 @@ middleware.checkGlobalPrivacySettings = function(req, res, next) {
if (!callerUID && !!parseInt(meta.config.privateUserInfo, 10)) {
if (res.locals.isAPI) {
- return res.json(403, 'not-allowed');
+ return res.status(403).json('not-allowed');
} else {
req.session.returnTo = req.url;
return res.redirect('login');
@@ -171,7 +171,7 @@ middleware.checkAccountPermissions = function(req, res, next) {
}
if (!uid) {
- return res.locals.isAPI ? res.json(404, 'not-found') : res.redirect(nconf.get('relative_path') + '/404');
+ return res.locals.isAPI ? res.status(404).json('not-found') : res.redirect(nconf.get('relative_path') + '/404');
}
if (parseInt(uid, 10) === callerUID) {
@@ -187,7 +187,7 @@ middleware.checkAccountPermissions = function(req, res, next) {
return next();
}
- res.locals.isAPI ? res.json(403, 'not-allowed') : res.redirect(nconf.get('relative_path') + '/403');
+ res.locals.isAPI ? res.status(403).json('not-allowed') : res.redirect(nconf.get('relative_path') + '/403');
});
});
};
diff --git a/src/routes/api.js b/src/routes/api.js
index 3e5512ac47..d6fbb258d4 100644
--- a/src/routes/api.js
+++ b/src/routes/api.js
@@ -43,12 +43,12 @@ function upload(req, res, filesIterator, next) {
deleteTempFiles(files);
if (err) {
- return res.send(500, err.message);
+ return res.status(500).send(err.message);
}
// IE8 - send it as text/html so browser won't trigger a file download for the json response
// malsup.com/jquery/form/#file-upload
- res.send(200, req.xhr ? images : JSON.stringify(images));
+ res.status(200).send(req.xhr ? images : JSON.stringify(images));
});
}
diff --git a/src/routes/authentication.js b/src/routes/authentication.js
index e8d4517ec1..2378bec052 100644
--- a/src/routes/authentication.js
+++ b/src/routes/authentication.js
@@ -29,7 +29,7 @@
req.logout();
}
- res.send(200);
+ res.status(200).send('');
}
function login(req, res, next) {
@@ -80,7 +80,7 @@
};
if(meta.config.allowLocalLogin !== undefined && parseInt(meta.config.allowLocalLogin, 10) === 0) {
- return res.send(404);
+ return res.status(404).send('');
}
if (req.body.username && utils.isEmailValid(req.body.username)) {
@@ -98,7 +98,7 @@
function register(req, res) {
if(meta.config.allowRegistration !== undefined && parseInt(meta.config.allowRegistration, 10) === 0) {
- return res.send(403);
+ return res.status(403).send('');
}
var userData = {};
diff --git a/src/routes/debug.js b/src/routes/debug.js
index 584a70a6b6..881d841bad 100644
--- a/src/routes/debug.js
+++ b/src/routes/debug.js
@@ -18,7 +18,7 @@ module.exports = function(app, middleware, controllers) {
if (data) {
res.send(data);
} else {
- res.json(404, {
+ res.status(404).json({
error: "User doesn't exist!"
});
}
@@ -30,7 +30,7 @@ module.exports = function(app, middleware, controllers) {
if (data) {
res.send(data);
} else {
- res.send(404, "Category doesn't exist!");
+ res.status(404).send("Category doesn't exist!");
}
});
});
@@ -40,7 +40,7 @@ module.exports = function(app, middleware, controllers) {
if (data) {
res.send(data);
} else {
- res.send(404, "Topic doesn't exist!");
+ res.status(404).send("Topic doesn't exist!");
}
});
});
@@ -50,7 +50,7 @@ module.exports = function(app, middleware, controllers) {
if (data) {
res.send(data);
} else {
- res.send(404, "Post doesn't exist!");
+ res.status(404).send("Post doesn't exist!");
}
});
});
diff --git a/src/routes/index.js b/src/routes/index.js
index 78d89406ce..b0ae2b4c2c 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -183,7 +183,7 @@ function catch404(req, res, next) {
res.status(404);
if (isClientScript.test(req.url)) {
- res.type('text/javascript').send(200, '');
+ res.type('text/javascript').status(200).send('');
} else if (isLanguage.test(req.url)) {
res.json(200, {});
} else if (req.accepts('html')) {
diff --git a/src/routes/meta.js b/src/routes/meta.js
index 9cfcc2faf8..dd888199dc 100644
--- a/src/routes/meta.js
+++ b/src/routes/meta.js
@@ -24,11 +24,11 @@ function sendSourceMap(req, res) {
}
function sendStylesheet(req, res, next) {
- res.type('text/css').send(200, meta.css.cache);
+ res.type('text/css').status(200).send(meta.css.cache);
}
function sendACPStylesheet(req, res, next) {
- res.type('text/css').send(200, meta.css.acpCache);
+ res.type('text/css').status(200).send(meta.css.acpCache);
}
function setupPluginSourceMapping(app) {