diff --git a/.gitignore b/.gitignore index 574ecfb7c..f39a432df 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,6 @@ examples/todoapp/node_modules *.tgz build docs/*.json -nbproject \ No newline at end of file +nbproject +deps/javascriptlint +deps/jsstyle diff --git a/examples/bench/bench.js b/examples/bench/bench.js index dc0e28968..52bae13ce 100644 --- a/examples/bench/bench.js +++ b/examples/bench/bench.js @@ -8,4 +8,5 @@ server.get('/echo/:name', function (req, res, next) { server.listen(8080, function () { console.log('ready'); -}); \ No newline at end of file +}); + diff --git a/examples/dtrace/demo.js b/examples/dtrace/demo.js index efb58e5a8..fc0446668 100644 --- a/examples/dtrace/demo.js +++ b/examples/dtrace/demo.js @@ -95,7 +95,7 @@ var server = restify.createServer({ } else if (Buffer.isBuffer(body)) { body = body.toString('base64'); } else { - switch (typeof(body)) { + switch (typeof body) { case 'boolean': case 'number': case 'string': diff --git a/examples/dtrace/hello.js b/examples/dtrace/hello.js index c6ead0ef9..039150207 100644 --- a/examples/dtrace/hello.js +++ b/examples/dtrace/hello.js @@ -28,4 +28,5 @@ server.get({ server.listen(8080, function () { console.log('listening: %s', server.url); -}); \ No newline at end of file +}); + diff --git a/examples/todoapp/lib/client.js b/examples/todoapp/lib/client.js index 7d7956360..c6bbec203 100644 --- a/examples/todoapp/lib/client.js +++ b/examples/todoapp/lib/client.js @@ -3,8 +3,6 @@ var util = require('util'); var assert = require('assert-plus'); -var bunyan = require('bunyan'); -var getopt = require('posix-getopt'); var restify = require('restify'); @@ -22,7 +20,6 @@ function TodoClient(options) { assert.optionalString(options.url, 'options.url'); assert.optionalString(options.version, 'options.version'); - var self = this; var ver = options.version || '~1.0'; this.client = restify.createClient({ diff --git a/examples/todoapp/lib/index.js b/examples/todoapp/lib/index.js index f5015180d..7d6ece8dc 100644 --- a/examples/todoapp/lib/index.js +++ b/examples/todoapp/lib/index.js @@ -3,4 +3,5 @@ module.exports = { createClient: require('./client').createClient, createServer: require('./server').createServer -}; \ No newline at end of file +}; + diff --git a/examples/todoapp/lib/server.js b/examples/todoapp/lib/server.js index 66e4aeeb6..acfbc4de8 100644 --- a/examples/todoapp/lib/server.js +++ b/examples/todoapp/lib/server.js @@ -96,13 +96,15 @@ function authenticate(req, res, next) { } var authz = req.authorization.basic; + if (!authz) { res.setHeader('WWW-Authenticate', 'Basic realm="todoapp"'); next(new restify.UnauthorizedError('authentication required')); return; } - if (authz.username !== req.allow.user || authz.password !== req.allow.pass) { + if (authz.username !== req.allow.user || + authz.password !== req.allow.pass) { next(new restify.ForbiddenError('invalid credentials')); return; } @@ -276,8 +278,9 @@ function loadTodos(req, res, next) { } else { req.todos = files; - if (req.params.name) + if (req.params.name) { req.todo = req.dir + '/' + req.params.name; + } req.log.debug({ todo: req.todo, @@ -312,12 +315,6 @@ function putTodo(req, res, next) { return; } - // Force the name to be what we sent this to - var todo = { - name: req.params.name, - task: req.params.task - }; - fs.writeFile(req.todo, JSON.stringify(req.body), function (err) { if (err) { req.log.warn(err, 'putTodo: unable to save'); @@ -369,7 +366,7 @@ function createServer(options) { server.use(restify.throttle({ burst: 10, rate: 5, - ip: true, + ip: true })); // Use the common stuff you probably want @@ -385,6 +382,7 @@ function createServer(options) { // at https://github.com/joyent/node-http-signature server.use(function setup(req, res, next) { req.dir = options.directory; + if (options.user && options.password) { req.allow = { user: options.user, diff --git a/examples/todoapp/main.js b/examples/todoapp/main.js index 643b1bf5e..dc7a8cfc1 100644 --- a/examples/todoapp/main.js +++ b/examples/todoapp/main.js @@ -2,9 +2,7 @@ var fs = require('fs'); var path = require('path'); -var util = require('util'); -var assert = require('assert-plus'); var bunyan = require('bunyan'); var getopt = require('posix-getopt'); var restify = require('restify'); @@ -59,7 +57,7 @@ var LOG = bunyan.createLogger({ */ function parseOptions() { var option; - var opts = {} + var opts = {}; var parser = new getopt.BasicParser('hvd:p:u:z:', process.argv); while ((option = parser.getopt()) !== undefined) { @@ -84,8 +82,10 @@ function parseOptions() { // Allows us to set -vvv -> this little hackery // just ensures that we're never < TRACE LOG.level(Math.max(bunyan.TRACE, (LOG.level() - 10))); - if (LOG.level() <= bunyan.DEBUG) + + if (LOG.level() <= bunyan.DEBUG) { LOG = LOG.child({src: true}); + } break; case 'z': @@ -103,8 +103,9 @@ function parseOptions() { function usage(msg) { - if (msg) + if (msg) { console.error(msg); + } var str = 'usage: ' + NAME + @@ -123,6 +124,7 @@ function usage(msg) { // First setup our 'database' var dir = path.normalize((options.directory || '/tmp') + '/todos'); + try { fs.mkdirSync(dir); } catch (e) { diff --git a/examples/todoapp/test/todo.test.js b/examples/todoapp/test/todo.test.js index 13ddd5e23..27a05acb2 100644 --- a/examples/todoapp/test/todo.test.js +++ b/examples/todoapp/test/todo.test.js @@ -3,7 +3,6 @@ var fs = require('fs'); var bunyan = require('bunyan'); -var nodeunit = require('nodeunit'); var restify = require('restify'); var todo = require('../lib'); @@ -58,8 +57,10 @@ exports.listEmpty = function (t) { t.ifError(err); t.ok(todos); t.ok(Array.isArray(todos)); - if (todos) + + if (todos) { t.equal(todos.length, 0); + } t.done(); }); }; @@ -70,6 +71,7 @@ exports.create = function (t) { CLIENT.create(task, function (err, todo) { t.ifError(err); t.ok(todo); + if (todo) { t.ok(todo.name); t.equal(todo.task, task); @@ -84,6 +86,7 @@ exports.listAndGet = function (t) { t.ifError(err); t.ok(todos); t.ok(Array.isArray(todos)); + if (todos) { t.equal(todos.length, 1); CLIENT.get(todos[0], function (err2, todo) { @@ -103,6 +106,7 @@ exports.update = function (t) { t.ifError(err); t.ok(todos); t.ok(Array.isArray(todos)); + if (todos) { t.equal(todos.length, 1); diff --git a/package.json b/package.json index 9aa78f047..b0de034fd 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,6 @@ "backoff": "^2.4.0", "bunyan": "1.3.4", "csv": "^0.4.0", - "deep-equal": "^1.0.0", "escape-regexp-component": "^1.0.2", "formidable": "^1.0.14", "http-signature": "^0.10.0",