Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ examples/todoapp/node_modules
*.tgz
build
docs/*.json
nbproject
nbproject
deps/javascriptlint
deps/jsstyle
3 changes: 2 additions & 1 deletion examples/bench/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ server.get('/echo/:name', function (req, res, next) {

server.listen(8080, function () {
console.log('ready');
});
});

2 changes: 1 addition & 1 deletion examples/dtrace/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
3 changes: 2 additions & 1 deletion examples/dtrace/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ server.get({

server.listen(8080, function () {
console.log('listening: %s', server.url);
});
});

3 changes: 0 additions & 3 deletions examples/todoapp/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');


Expand All @@ -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({
Expand Down
3 changes: 2 additions & 1 deletion examples/todoapp/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
module.exports = {
createClient: require('./client').createClient,
createServer: require('./server').createServer
};
};

16 changes: 7 additions & 9 deletions examples/todoapp/lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
12 changes: 7 additions & 5 deletions examples/todoapp/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand All @@ -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':
Expand All @@ -103,8 +103,9 @@ function parseOptions() {


function usage(msg) {
if (msg)
if (msg) {
console.error(msg);
}

var str = 'usage: ' +
NAME +
Expand All @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions examples/todoapp/test/todo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var fs = require('fs');

var bunyan = require('bunyan');
var nodeunit = require('nodeunit');
var restify = require('restify');

var todo = require('../lib');
Expand Down Expand Up @@ -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();
});
};
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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);

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down