Skip to content

Commit d2b9719

Browse files
Merge pull request #173 from jerone/hci
Clean up
2 parents c883fe5 + 3a70a72 commit d2b9719

File tree

85 files changed

+1358
-1354
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1358
-1354
lines changed

app.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ var group = require('./controllers/group');
1818
var discussion = require('./controllers/discussion');
1919
var issue = require('./controllers/issue');
2020
var scriptStorage = require('./controllers/scriptStorage');
21-
var statusCodePage = require('./libs/templateHelpers').statusCodePage;
22-
23-
var modelParser = require('./libs/modelParser');
2421

22+
var statusCodePage = require('./libs/templateHelpers').statusCodePage;
2523
var modifySessions = require('./libs/modifySessions');
24+
2625
var settings = require('./models/settings.json');
26+
2727
var connectStr = process.env.CONNECT_STRING || settings.connect;
2828
var sessionSecret = process.env.SESSION_SECRET || settings.secret;
2929
var db = mongoose.connection;
30-
var dbOptions = { server : { socketOptions : { keepAlive: 1 } } };
30+
var dbOptions = { server: { socketOptions: { keepAlive: 1 } } };
3131

3232
app.set('port', process.env.PORT || 8080);
3333

3434
// Connect to the database
3535
mongoose.connect(connectStr, dbOptions);
3636
db.on('error', console.error.bind(console, 'connection error:'));
37-
db.once('open', function () {
37+
db.once('open', function() {
3838
app.listen(app.get('port'));
3939
});
4040

41-
app.configure(function(){
41+
app.configure(function() {
4242
var sessionStore = new MongoStore({ mongoose_connection: db });
4343

4444
// See https://hacks.mozilla.org/2013/01/building-a-node-js-server-that-wont-melt-a-node-js-holiday-season-part-5/
45-
app.use(function (req, res, next) {
45+
app.use(function(req, res, next) {
4646
// check if we're toobusy
4747
if (toobusy()) {
4848
statusCodePage(req, res, next, {
@@ -56,13 +56,12 @@ app.configure(function(){
5656

5757
// Force HTTPS
5858
if (app.get('port') === 443) {
59-
app.use(function (req, res, next) {
59+
app.use(function(req, res, next) {
6060
res.setHeader('Strict-Transport-Security',
6161
'max-age=8640000; includeSubDomains');
6262

6363
if (req.headers['x-forwarded-proto'] !== 'https') {
64-
return res.redirect(301, 'https://' + req.headers.host
65-
+ encodeURI(req.url));
64+
return res.redirect(301, 'https://' + req.headers.host + encodeURI(req.url));
6665
}
6766

6867
next();
@@ -96,7 +95,7 @@ app.configure(function(){
9695
});
9796

9897
// Build the route regex for model lists
99-
function listRegex (root, type) {
98+
function listRegex(root, type) {
10099
var slash = '\/';
101100
if (root === slash) { slash = ''; }
102101
return new RegExp('^' + root +
@@ -115,7 +114,7 @@ function app_route(path) {
115114
r.all = function(cb) {
116115
app.all.call(app, path, cb);
117116
};
118-
methods.forEach(function(method){
117+
methods.forEach(function(method) {
119118
r[method] = function(cb) {
120119
app[method].call(app, path, cb);
121120
return r;
@@ -153,7 +152,6 @@ app_route('/user/add/lib/new').get(script.lib(user.editScript)).post(script.lib(
153152
app_route('/user/add/scripts/upload').post(user.uploadScript);
154153
app_route('/user/add/lib/upload').post(script.lib(user.uploadScript));
155154

156-
157155
// Script routes
158156
app_route('/scripts/:username/:namespace?/:scriptname').get(script.view);
159157
app_route('/script/:username/:namespace?/:scriptname/edit').get(script.edit).post(script.edit);
@@ -165,7 +163,7 @@ app.get('/install/:username/:namespace?/:scriptname', scriptStorage.sendScript);
165163
app.get('/meta/:username/:namespace?/:scriptname', scriptStorage.sendMeta);
166164
app.get('/vote/scripts/:username/:namespace?/:scriptname/:vote', script.vote);
167165
app.post('/github/hook', scriptStorage.webhook);
168-
app.post('/github/service', function (req, res, next) { next(); });
166+
app.post('/github/service', function(req, res, next) { next(); });
169167

170168
// Library routes
171169
app.get(listRegex('\/toolbox', 'lib'), main.toolbox);
@@ -180,7 +178,7 @@ app.get('/vote/libs/:username/:scriptname/:vote', script.lib(script.vote));
180178

181179
// Issues routes
182180
app_route('/:type(scripts|libs)/:username/:namespace?/:scriptname/issues/:open(closed)?').get(issue.list);
183-
// app_route('/:type(scripts|libs)/:username/:namespace?/:scriptname/issues/:topic').get(issue.view);
181+
//app_route('/:type(scripts|libs)/:username/:namespace?/:scriptname/issues/:topic').get(issue.view);
184182
app_route('/:type(scripts|libs)/:username/:namespace?/:scriptname/issue/new').get(issue.open).post(issue.open);
185183
app_route('/:type(scripts|libs)/:username/:namespace?/:scriptname/issues/:topic').get(issue.view);
186184

@@ -201,9 +199,8 @@ app_route('/mod/removed').get(moderation.removedItemListPage);
201199
app_route('/mod/removed/:id').get(moderation.removedItemPage);
202200
app.get('/flag/users/:username/:unflag?', user.flag);
203201
app.get('/flag/scripts/:username/:namespace?/:scriptname/:unflag?', script.flag);
204-
app.get('/flag/libs/:username/:scriptname/:unflag?', script.lib(script.flag)); //
205-
app.get(listRegex('\/flagged(?:\/([^\/]+?))?', 'user|script'),
206-
moderation.flagged); //
202+
app.get('/flag/libs/:username/:scriptname/:unflag?', script.lib(script.flag));
203+
app.get(listRegex('\/flagged(?:\/([^\/]+?))?', 'user|script'), moderation.flagged);
207204
app.get(listRegex('\/graveyard(?:\/([^\/]+?))?', ''), moderation.graveyard);
208205
app.get(/^\/remove\/(.+?)\/(.+)$/, remove.rm);
209206

@@ -237,10 +234,9 @@ app.get(listRegex('\/', 'script'), main.home);
237234

238235
// Fallback routes
239236
app.use(express.static(__dirname + '/public'));
240-
app.use(function (req, res, next) {
237+
app.use(function(req, res, next) {
241238
statusCodePage(req, res, next, {
242239
statusCode: 404,
243240
statusMessage: 'This is not the page you\'re are looking for.',
244241
});
245242
});
246-

controllers/_template.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ var modelQuery = require('../libs/modelQuery');
1616
// Generate a bootstrap3 pagination widget.
1717
var getDefaultPagination = require('../libs/templateHelpers').getDefaultPagination;
1818

19-
2019
//--- Views
21-
exports.example = function (req, res, next) {
20+
exports.example = function(req, res, next) {
2221
var authedUser = req.session.user;
2322

2423
//
@@ -38,16 +37,15 @@ exports.example = function (req, res, next) {
3837
options.pageMetaKeywords = pageMetaKeywords.join(', ');
3938

4039
//--- Tasks
41-
// ...
4240

4341
//---
44-
function preRender(){};
45-
function render(){ res.render('pages/_templatePage', options); }
46-
function asyncComplete(){ preRender(); render(); }
42+
function preRender() { };
43+
function render() { res.render('pages/_templatePage', options); }
44+
function asyncComplete() { preRender(); render(); }
4745
async.parallel(tasks, asyncComplete);
4846
};
4947

50-
exports.example = function (req, res, next) {
48+
exports.example = function(req, res, next) {
5149
var authedUser = req.session.user;
5250

5351
//
@@ -70,17 +68,16 @@ exports.example = function (req, res, next) {
7068
var scriptListQuery = Script.find();
7169

7270
// Scripts: Query: isLib=false
73-
scriptListQuery.find({isLib: false});
71+
scriptListQuery.find({ isLib: false });
7472

7573
// Scripts: Query: Search
7674
if (req.query.q)
7775
modelQuery.parseScriptSearchQuery(scriptListQuery, req.query.q);
7876

7977
// Scripts: Query: Sort
80-
modelQuery.parseModelListSort(scriptListQuery, req.query.orderBy, req.query.orderDir, function(){
78+
modelQuery.parseModelListSort(scriptListQuery, req.query.orderBy, req.query.orderDir, function() {
8179
scriptListQuery.sort('-rating -installs -updated');
8280
});
83-
8481

8582
// Pagination
8683
var pagination = getDefaultPagination(req);
@@ -90,10 +87,10 @@ exports.example = function (req, res, next) {
9087

9188
// Pagination
9289
tasks.push(pagination.getCountTask(scriptListQuery));
93-
90+
9491
// Scripts
95-
tasks.push(function (callback) {
96-
scriptListQuery.exec(function(err, scriptDataList){
92+
tasks.push(function(callback) {
93+
scriptListQuery.exec(function(err, scriptDataList) {
9794
if (err) {
9895
callback();
9996
} else {
@@ -104,12 +101,12 @@ exports.example = function (req, res, next) {
104101
});
105102

106103
//---
107-
function preRender(){
104+
function preRender() {
108105
// Pagination
109106
options.paginationRendered = pagination.renderDefault(req);
110107
};
111-
function render(){ res.render('pages/_templatePage', options); }
112-
function asyncComplete(){ preRender(); render(); }
108+
function render() { res.render('pages/_templatePage', options); }
109+
function asyncComplete() { preRender(); render(); }
113110
async.parallel(tasks, asyncComplete);
114111
};
115112

0 commit comments

Comments
 (0)