Skip to content

Commit

Permalink
Merge pull request #417 from Martii/updateToExpress4
Browse files Browse the repository at this point in the history
Move to latest *express* 4 stable

Auto-merge... fully retested on dev.
  • Loading branch information
Martii committed Nov 18, 2014
2 parents 7b044da + 1b595bb commit 396ea27
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 155 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Repository | Reference | Recent Version
[connect-mongo][connect-mongoGHUrl] | [Documentation][connect-mongoDOCUrl] | [![NPM version][connect-mongoNPMVersionImage]][connect-mongoNPMUrl]
[cookie-parser][cookie-parserGHUrl] | [Documentation][cookie-parserDOCUrl] | [![NPM version][cookie-parserNPMVersionImage]][cookie-parserNPMUrl]
[express][expressGHUrl] | [Documentation][expressDOCUrl] | [![NPM version][expressNPMVersionImage]][expressNPMUrl]
[express-minify][express-minifyGHUrl] | [Documentation][express-minifyDOCUrl] | [![NPM version][express-minifyNPMVersionImage]][express-minifyNPMUrl]
[express-session][express-sessionGHUrl] | [Documentation][express-sessionDOCUrl] | [![NPM version][express-sessionNPMVersionImage]][express-sessionNPMUrl]
[fakes3][fakes3GHUrl] | [Documentation][fakes3DOCUrl] | [![GEM version][fakes3GEMVersionImage]][fakes3GEMUrl]
[font-awesome][font-awesomeGHUrl] | [Documentation][font-awesomeDOCUrl] | [![NPM version][font-awesomeNPMVersionImage]][font-awesomeNPMUrl]
Expand Down Expand Up @@ -167,6 +168,11 @@ Repository | Reference | Recent Version | Referenced
[expressNPMUrl]: https://www.npmjs.org/package/express
[expressNPMVersionImage]: https://img.shields.io/npm/v/express.svg?style=flat

[express-minifyGHUrl]: https://github.com/breeswish/express-minify
[express-minifyDOCUrl]: https://github.com/breeswish/express-minify/blob/master/README.md
[express-minifyNPMUrl]: https://www.npmjs.org/package/express-minify
[express-minifyNPMVersionImage]: https://img.shields.io/npm/v/express-minify.svg?style=flat

[express-sessionGHUrl]: https://github.com/expressjs/session
[express-sessionDOCUrl]: https://github.com/expressjs/session/blob/master/README.md
[express-sessionNPMUrl]: https://npmjs.org/package/express-session
Expand Down
1 change: 0 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ app.use(session({
}));
app.use(passport.initialize());
app.use(modifySessions.init(sessionStore));
app.use(app.router);
app.use(favicon(__dirname + '/public/images/favicon.ico'));

// Set up the views
Expand Down
4 changes: 2 additions & 2 deletions controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ exports.userAdmin = function (aReq, aRes, aNext) {
// View everything about a particular user
// This is mostly for debugging in production
exports.adminUserView = function (aReq, aRes, aNext) {
var id = aReq.route.params.id;
var id = aReq.params.id;
var thisUser = aReq.session.user;

if (!userIsAdmin(aReq)) { return aNext(); }
Expand Down Expand Up @@ -157,7 +157,7 @@ exports.adminJsonView = function (aReq, aRes, aNext) {
exports.adminUserUpdate = function (aReq, aRes, aNext) {
var authedUser = aReq.session.user;

var username = aReq.route.params.username;
var username = aReq.params.username;

User.findOne({
name: username
Expand Down
4 changes: 2 additions & 2 deletions controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Strategy.find({}, function (aErr, aStrategies) {

exports.auth = function (aReq, aRes, aNext) {
var user = aReq.session.user;
var strategy = aReq.body.auth || aReq.route.params.strategy;
var strategy = aReq.body.auth || aReq.params.strategy;
var username = aReq.body.username || aReq.session.username;

function auth() {
Expand Down Expand Up @@ -105,7 +105,7 @@ exports.auth = function (aReq, aRes, aNext) {
};

exports.callback = function (aReq, aRes, aNext) {
var strategy = aReq.route.params.strategy;
var strategy = aReq.params.strategy;
var username = aReq.session.username;
var newstrategy = aReq.session.newstrategy;
var strategyInstance = null;
Expand Down
14 changes: 7 additions & 7 deletions controllers/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ exports.categoryListPage = function (aReq, aRes, aNext) {
exports.list = function (aReq, aRes, aNext) {
var authedUser = aReq.session.user;

var categorySlug = aReq.route.params.category;
var categorySlug = aReq.params.category;

var category = _.findWhere(categories, { slug: categorySlug });
if (!category)
Expand Down Expand Up @@ -213,8 +213,8 @@ exports.findDiscussion = findDiscussion;
exports.show = function (aReq, aRes, aNext) {
var authedUser = aReq.session.user;

var categorySlug = aReq.route.params.category;
var topic = aReq.route.params.topic;
var categorySlug = aReq.params.category;
var topic = aReq.params.topic;

var category = _.findWhere(categories, { slug: categorySlug });
if (!category)
Expand Down Expand Up @@ -289,7 +289,7 @@ exports.newTopic = function (aReq, aRes, aNext) {
if (!authedUser)
return aRes.redirect('/login');

var categorySlug = aReq.route.params.category;
var categorySlug = aReq.params.category;

var category = _.findWhere(categories, { slug: categorySlug });
if (!category)
Expand Down Expand Up @@ -403,7 +403,7 @@ exports.createTopic = function (aReq, aRes, aNext) {
if (!authedUser)
return aRes.redirect('/login');

var categorySlug = aReq.route.params.category;
var categorySlug = aReq.params.category;
var topic = aReq.body['discussion-topic'];
var content = aReq.body['comment-content'];

Expand Down Expand Up @@ -436,8 +436,8 @@ exports.createTopic = function (aReq, aRes, aNext) {

// post route to create a new comment on an existing discussion
exports.createComment = function (aReq, aRes, aNext) {
var category = aReq.route.params.category;
var topic = aReq.route.params.topic;
var category = aReq.params.category;
var topic = aReq.params.topic;
var user = aReq.session.user;
var content = aReq.body['comment-content'];
var commentId = aReq.body['comment-id']; // for editing
Expand Down
2 changes: 1 addition & 1 deletion controllers/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.view = function (aReq, aRes, aNext) {
var tasks = [];

var documentPath = null;
var document = aReq.route.params.document;
var document = aReq.params.document;
var then = null;

// Session
Expand Down
6 changes: 3 additions & 3 deletions controllers/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function cleanGroupName(aName) {
exports.search = function (aReq, aRes) {
var queryStr = '';
var queryRegex = null;
var addTerm = aReq.route.params.addTerm;
var term = cleanGroupName(aReq.route.params.term);
var addTerm = aReq.params.addTerm;
var term = cleanGroupName(aReq.params.term);
var terms = term.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1').split(/\s+/);
var results = null;

Expand Down Expand Up @@ -227,7 +227,7 @@ var setupGroupSidePanel = function (aOptions) {
exports.view = function (aReq, aRes, aNext) {
var authedUser = aReq.session.user;

var groupNameSlug = aReq.route.params.groupname;
var groupNameSlug = aReq.params.groupname;
var groupName = groupNameSlug.replace(/_+/g, ' ');

Group.findOne({
Expand Down
28 changes: 14 additions & 14 deletions controllers/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ var orderDir = require('../libs/templateHelpers').orderDir;
exports.list = function (aReq, aRes, aNext) {
var authedUser = aReq.session.user;

var type = aReq.route.params.type;
var username = aReq.route.params.username;
var scriptname = aReq.route.params.scriptname;
var open = aReq.route.params.open !== 'closed';
var type = aReq.params.type;
var username = aReq.params.username;
var scriptname = aReq.params.scriptname;
var open = aReq.params.open !== 'closed';

var installNameSlug = username + '/' + scriptname;

Expand Down Expand Up @@ -143,10 +143,10 @@ exports.list = function (aReq, aRes, aNext) {
exports.view = function (aReq, aRes, aNext) {
var authedUser = aReq.session.user;

var type = aReq.route.params.type;
var username = aReq.route.params.username;
var scriptname = aReq.route.params.scriptname;
var topic = aReq.route.params.topic;
var type = aReq.params.type;
var username = aReq.params.username;
var scriptname = aReq.params.scriptname;
var topic = aReq.params.topic;

var installNameSlug = username + '/' + scriptname;

Expand Down Expand Up @@ -245,7 +245,7 @@ exports.open = function (aReq, aRes, aNext) {
var topic = aReq.body['discussion-topic'];
var content = aReq.body['comment-content'];

var type = aReq.route.params.type;
var type = aReq.params.type;
var installNameSlug = scriptStorage.getInstallName(aReq);

Script.findOne({
Expand Down Expand Up @@ -309,8 +309,8 @@ exports.open = function (aReq, aRes, aNext) {

// post route to add a new comment to a discussion on an issue
exports.comment = function (aReq, aRes, aNext) {
var type = aReq.route.params.type;
var topic = aReq.route.params.topic;
var type = aReq.params.type;
var topic = aReq.params.topic;
var installName = scriptStorage.getInstallName(aReq);
var category = type + '/' + installName + '/issues';
var user = aReq.session.user;
Expand All @@ -337,11 +337,11 @@ exports.comment = function (aReq, aRes, aNext) {

// Open or close and issue you are allowed
exports.changeStatus = function (aReq, aRes, aNext) {
var type = aReq.route.params.type;
var topic = aReq.route.params.topic;
var type = aReq.params.type;
var topic = aReq.params.topic;
var installName = scriptStorage.getInstallName(aReq);
var category = type + '/' + installName + '/issues';
var action = aReq.route.params.action;
var action = aReq.params.action;
var user = aReq.session.user;
var changed = false;

Expand Down
2 changes: 1 addition & 1 deletion controllers/moderation.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var orderDir = require('../libs/templateHelpers').orderDir;
exports.removedItemPage = function (aReq, aRes, aNext) {
var authedUser = aReq.session.user;

var removedItemId = aReq.route.params.id;
var removedItemId = aReq.params.id;

//
var options = {};
Expand Down
4 changes: 2 additions & 2 deletions controllers/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ var destroySessions = require('../libs/modifySessions').destroy;

// Simple controller to remove content and save it in the graveyard
exports.rm = function (aReq, aRes, aNext) {
var type = aReq.route.params[0];
var path = aReq.route.params[1];
var type = aReq.params[0];
var path = aReq.params[1];
var thisUser = aReq.session.user;

switch (type) {
Expand Down
26 changes: 13 additions & 13 deletions controllers/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ var pageMetadata = require('../libs/templateHelpers').pageMetadata;
// Let controllers know this is a `new` route
exports.new = function (aController) {
return (function (aReq, aRes, aNext) {
aReq.route.params.isNew = true;
aReq.params.isNew = true;
aController(aReq, aRes, aNext);
});
};

// Let controllers know this is a `lib` route
exports.lib = function (aController) {
return (function (aReq, aRes, aNext) {
aReq.route.params.isLib = true;
aReq.params.isLib = true;
aController(aReq, aRes, aNext);
});
};
Expand Down Expand Up @@ -292,9 +292,9 @@ exports.view = function (aReq, aRes, aNext) {
var authedUser = aReq.session.user;

var installNameSlug = scriptStorage.getInstallName(aReq);
var scriptAuthor = aReq.route.params.username;
var scriptNameSlug = aReq.route.params.scriptname;
var isLib = aReq.route.params.isLib;
var scriptAuthor = aReq.params.username;
var scriptNameSlug = aReq.params.scriptname;
var isLib = aReq.params.isLib;

Script.findOne({
installName: scriptStorage
Expand Down Expand Up @@ -354,12 +354,12 @@ exports.edit = function (aReq, aRes, aNext) {
if (!authedUser) { return aRes.redirect('/login'); }

// Support routes lacking the :username. TODO: Remove this functionality.
aReq.route.params.username = authedUser.name.toLowerCase();
aReq.params.username = authedUser.name.toLowerCase();

var installNameSlug = scriptStorage.getInstallName(aReq);
var scriptAuthor = aReq.route.params.username;
var scriptNameSlug = aReq.route.params.scriptname;
var isLib = aReq.route.params.isLib;
var scriptAuthor = aReq.params.username;
var scriptNameSlug = aReq.params.scriptname;
var isLib = aReq.params.isLib;

Script.findOne({
installName: scriptStorage
Expand Down Expand Up @@ -436,10 +436,10 @@ exports.edit = function (aReq, aRes, aNext) {

// Script voting
exports.vote = function (aReq, aRes, aNext) {
var isLib = aReq.route.params.isLib;
var isLib = aReq.params.isLib;
var installName = scriptStorage.getInstallName(aReq)
+ (isLib ? '.js' : '.user.js');
var vote = aReq.route.params.vote;
var vote = aReq.params.vote;
var user = aReq.session.user;
var url = aReq._parsedUrl.pathname.split('/');
var unvote = false;
Expand Down Expand Up @@ -520,9 +520,9 @@ exports.vote = function (aReq, aRes, aNext) {

// Script flagging
exports.flag = function (aReq, aRes, aNext) {
var isLib = aReq.route.params.isLib;
var isLib = aReq.params.isLib;
var installName = scriptStorage.getInstallName(aReq);
var unflag = aReq.route.params.unflag;
var unflag = aReq.params.unflag;

Script.findOne({ installName: scriptStorage
.caseInsensitive(installName + (isLib ? '.js' : '.user.js')) },
Expand Down
8 changes: 5 additions & 3 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ if (isPro) {
}

function getInstallName(aReq) {
return aReq.route.params.username + '/' + aReq.route.params.scriptname;
return aReq.params.username + '/' + aReq.params.scriptname;
}
exports.getInstallName = getInstallName;

function caseInsensitive (aInstallName) {
function caseInsensitive(aInstallName) {
return new RegExp('^' + aInstallName.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1")
+ '$', 'i');
}
Expand Down Expand Up @@ -73,10 +73,11 @@ exports.sendScript = function (aReq, aRes, aNext) {

// Send the script
aRes.set('Content-Type', 'text/javascript; charset=UTF-8');
aRes._no_minify = true;
aStream.pipe(aRes);

// Don't count installs on raw source route
if (aScript.isLib || aReq.route.params.type) { return; }
if (aScript.isLib || aReq.params.type) { return; }

// Update the install count
++aScript.installs;
Expand All @@ -101,6 +102,7 @@ exports.sendMeta = function (aReq, aRes, aNext) {
if (!aScript) { return aNext(); }

aRes.set('Content-Type', 'text/javascript; charset=UTF-8');
aRes._no_minify = true;
meta = aScript.meta; // NOTE: Watchpoint

aRes.write('// ==UserScript==\n');
Expand Down

0 comments on commit 396ea27

Please sign in to comment.