Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Commit

Permalink
disabling JSONP from ExpressJS config and replacing all responses of …
Browse files Browse the repository at this point in the history
…jsonp() to json()
  • Loading branch information
lirantal committed Jul 6, 2014
1 parent d977daf commit a322cba
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
3 changes: 0 additions & 3 deletions config/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ module.exports = function(app, passport, db) {
// set .html as the default extension
app.set('view engine', 'html');

// Enable jsonp
app.enable('jsonp callback');

// The cookieParser should be above session
app.use(cookieParser());

Expand Down
18 changes: 9 additions & 9 deletions packages/articles/server/controllers/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ exports.create = function(req, res) {

article.save(function(err) {
if (err) {
return res.jsonp(500, {
return res.json(500, {
error: 'Cannot save the article'
});
}
res.jsonp(article);
res.json(article);

});
};
Expand All @@ -48,11 +48,11 @@ exports.update = function(req, res) {

article.save(function(err) {
if (err) {
return res.jsonp(500, {
return res.json(500, {
error: 'Cannot update the article'
});
}
res.jsonp(article);
res.json(article);

});
};
Expand All @@ -65,11 +65,11 @@ exports.destroy = function(req, res) {

article.remove(function(err) {
if (err) {
return res.jsonp(500, {
return res.json(500, {
error: 'Cannot delete the article'
});
}
res.jsonp(article);
res.json(article);

});
};
Expand All @@ -78,7 +78,7 @@ exports.destroy = function(req, res) {
* Show an article
*/
exports.show = function(req, res) {
res.jsonp(req.article);
res.json(req.article);
};

/**
Expand All @@ -87,11 +87,11 @@ exports.show = function(req, res) {
exports.all = function(req, res) {
Article.find().sort('-created').populate('user', 'name username').exec(function(err, articles) {
if (err) {
return res.jsonp(500, {
return res.json(500, {
error: 'Cannot list the articles'
});
}
res.jsonp(articles);
res.json(articles);

});
};
2 changes: 1 addition & 1 deletion packages/system/server/routes/menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = function(System, app, auth, database) {
defaultMenu: defaultMenu
});

res.jsonp(items);
res.json(items);
});

};
10 changes: 5 additions & 5 deletions packages/users/server/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ exports.create = function(req, res, next) {
* Send User
*/
exports.me = function(req, res) {
res.jsonp(req.user || null);
res.json(req.user || null);
};

/**
Expand All @@ -136,10 +136,10 @@ exports.user = function(req, res, next, id) {
exports.resetpassword = function(req, res, next) {
User.findOne({ resetPasswordToken: req.params.token, resetPasswordExpires: { $gt: Date.now() } }, function(err, user) {
if (err) {
return res.status(400).jsonp({msg: err});
return res.status(400).json({msg: err});
}
if (!user) {
return res.status(400).jsonp({msg: 'Token invalid or expired'});
return res.status(400).json({msg: 'Token invalid or expired'});
}
req.assert('password', 'Password must be between 8-20 characters long').len(8, 20);
req.assert('confirmPassword', 'Passwords do not match').equals(req.body.password);
Expand Down Expand Up @@ -209,10 +209,10 @@ exports.forgotpassword = function(req, res, next) {
'message' : 'User does not exist',
'status' : 'danger'
};
res.jsonp(response);
res.json(response);
}
else {
res.jsonp(response);
res.json(response);
}
});
};

0 comments on commit a322cba

Please sign in to comment.