Skip to content

Commit 6e80380

Browse files
committed
Adds Gulp and JSHint
1 parent e34d514 commit 6e80380

File tree

11 files changed

+43
-25
lines changed

11 files changed

+43
-25
lines changed

.jshintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
public/javascripts/vendor

.jshintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"node": true
3+
}

cache.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ exports.createStore = function() {
88
stdTTL: config.cache.ttl,
99
useClones: false,
1010
});
11-
}
11+
};

config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ config.env = process.env.NODE_ENV || 'development';
66

77
config.express = {
88
port: process.env.PORT || 3000,
9-
}
9+
};
1010

1111
config.mongodb = {
1212
uri: process.env.MONGOLAB_URI || 'mongodb://localhost:27017/shellshare',
1313
capped_size_limit: 50 * 1024, // 50 KB is more than enough for a full terminal screen
1414
authorizations_ttl: 86400, // 1 day
15-
}
15+
};
1616

1717
config.cache = {
1818
ttl: 3600,
19-
}
19+
};

db.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var MongoClient = require('mongodb').MongoClient;
44

55
var state = {
66
db: null,
7-
}
7+
};
88

99
exports.connect = function(url, done) {
1010
if (state.db) return done();
@@ -13,19 +13,19 @@ exports.connect = function(url, done) {
1313
if (err) return done(err);
1414
state.db = db;
1515
done();
16-
})
17-
}
16+
});
17+
};
1818

1919
exports.get = function() {
2020
return state.db;
21-
}
21+
};
2222

2323
exports.close = function(done) {
2424
if (state.db) {
2525
state.db.close(function(err, result) {
2626
state.db = null;
2727
state.mode = null;
2828
done(err);
29-
})
29+
});
3030
}
31-
}
31+
};

gulpfile.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
var gulp = require('gulp');
4+
var jshint = require('gulp-jshint');
5+
6+
gulp.task('lint', function() {
7+
gulp.src('./**/*.js')
8+
.pipe(jshint())
9+
.pipe(jshint.reporter('default'));
10+
});

models/authorization.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ function _upsertAuthorization(room, secret) {
5757

5858
module.exports = {
5959
isAuthorized: isAuthorized,
60-
}
60+
};

models/rooms.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function push(room, size, message, callback) {
3131
function all(room, callback) {
3232
_collection(room, function(collection) {
3333
collection.find({}).toArray(function(err, items) {
34-
if (err || items.length == 0) {
34+
if (err || items.length === 0) {
3535
callback(err, items);
3636
} else {
3737
var messageAscii = items.map(function (item) {
@@ -59,4 +59,4 @@ module.exports = {
5959
push: push,
6060
all: all,
6161
drop: drop,
62-
}
62+
};

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212
"body-parser": "1.14.1",
1313
"errorhandler": "1.4.2",
1414
"express": "4.13.3",
15+
"gulp": "3.9.0",
1516
"jade": "1.11.0",
1617
"mongodb": "2.0.46",
1718
"morgan": "1.6.1",
1819
"node-cache": "3.0.0",
1920
"socket.io": "1.3.7"
21+
},
22+
"devDependencies": {
23+
"gulp-jshint": "^1.11.2"
2024
}
2125
}

public/javascripts/room.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// FIXME: Ugly monkey patch to avoid term.js capturing the key presses,
1414
// as we're just using term.js as read-only. There should be a better way
1515
// to do this, but I couldn't find it.
16-
}
16+
};
1717

1818
socket.emit('join', room);
1919
socket.on('usersCount', function (onlineUsers) {
@@ -56,7 +56,7 @@
5656
}
5757

5858
currentSize = size;
59-
};
59+
}
6060

6161
// Init terminal with a default size.
6262
onSize('{"cols": 80, "rows": 40}');

routes/rooms.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ router.get('/:room', function(req, res, next) {
1515

1616
/* POST room. */
1717
router.post('/:room', function(req, res, next) {
18-
var room = req.url;
19-
var secret = req.get('Authorization');
20-
21-
authorizeOrDie(room, secret, function() {
18+
authorizeOrDie(req, res, function() {
19+
var room = req.url;
2220
var size = req.body.size;
2321
var message = req.body.message;
2422

@@ -32,17 +30,18 @@ router.post('/:room', function(req, res, next) {
3230

3331
/* DELETE room */
3432
router.delete('/:room', function(req, res, next) {
35-
var room = req.url;
36-
var secret = req.get('Authorization');
37-
38-
authorizeOrDie(room, secret, function() {
33+
authorizeOrDie(req, res, function() {
34+
var room = req.url;
3935
roomsModel.drop(room, function(err, col) {
4036
});
4137
res.sendStatus(202);
4238
});
4339
});
4440

45-
function authorizeOrDie(room, secret, callback) {
41+
function authorizeOrDie(req, res, callback) {
42+
var room = req.url;
43+
var secret = req.get('Authorization');
44+
4645
// FIXME: secret might be empty
4746
authorizationModel.isAuthorized(room, secret, function(authorized) {
4847
if (!authorized) {
@@ -105,4 +104,4 @@ module.exports = function(_roomPrefix, _io) {
105104

106105
setupSockets();
107106
return router;
108-
}
107+
};

0 commit comments

Comments
 (0)