Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
make new jshint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
hoegaarden committed Jul 28, 2013
1 parent f26e9c5 commit e4b7313
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 65 deletions.
4 changes: 3 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"laxcomma" : "true"
"laxcomma" : true
, "node" : true
, "curly" : false
}
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"use strict";

var app = require('./lib/express')
, http = require('http')
, https = require('https')
, fs = require('fs')
, http_port = process.env.PORT_HTTP || process.env.PORT || 8080
, https_port = process.env.PORT_HTTPS || 4430
;

function listening() {
var listening = function listening() {
var addr = this.address();
var type = this.hasOwnProperty('key') ? 'https' : 'http';
console.log('* listening on %s://%s:%d', type, addr.address, addr.port);
}
};

function startHttp() {
var port = process.env.npm_package_config_http_port;
Expand Down
14 changes: 4 additions & 10 deletions lib/express.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"use strict";

var express = require('express')
, app = express()
, routes = require('../routes')
, ormloader = require('../models')
, ratelimit = require('../lib/ratelimit.js')
, paging = require('../lib/paging.js')
;
module.exports = app;

Expand All @@ -18,16 +21,7 @@ app.configure(function(){
app.use(ratelimit());
app.use(express.favicon());
app.use(ormloader());


app.use(function(req, res, next){
req.page = {
limit : Math.min( +req.query.limit || 25 , 200 )
, offset : +req.query.offset || 0
};
return next();
});

app.use(paging());
});

routes(app);
Expand Down
5 changes: 3 additions & 2 deletions lib/hal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";

function addHAL(type, name, obj, force_array) {
var addHAL = function addHAL(type, name, obj, force_array) {
if (! this.hasOwnProperty(type) )
this[type] = {};

Expand All @@ -13,7 +14,7 @@ function addHAL(type, name, obj, force_array) {
}

return this;
}
};


module.exports = {
Expand Down
31 changes: 31 additions & 0 deletions lib/paging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use strict";

function sorter(a, b){
return (a - b);
}

function gate(val, def, min, max) {
var vals = [ +val || def ];

if ('undefined' !== typeof min)
vals.push(min);
if ('undefined' !== typeof max)
vals.push(max);

if (vals.length < 2)
return def;

return (vals.sort(sorter))[1];
}

module.exports = function(key) {
key = key || 'page';

return function(req, res, next) {
req[key] = {
limit : gate(req.query.limit, 25, 1, 200)
, offset : gate(req.query.offset, 0)
};
return next();
};
};
2 changes: 2 additions & 0 deletions lib/ratelimit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

var limiter = require('connect-ratelimit');

var default_conf = {
Expand Down
2 changes: 2 additions & 0 deletions migrations/20130613000000-install-hstore.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

module.exports.up = function(db, cb) {
db.runSql('create extension if not exists hstore', cb);
};
Expand Down
3 changes: 2 additions & 1 deletion migrations/20130613213125-init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var dbm = require('db-migrate');
"use strict";

var here = require('here').here;
var async = require('async');

Expand Down
1 change: 1 addition & 0 deletions migrations/20130629121557-add-geodata.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";

exports.up = function(db, callback) {
/* if location == null, it's an anon. node we have no info about yet */
Expand Down
2 changes: 2 additions & 0 deletions migrations/20130727090718-node-upload-return-ids.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

var here = require('here').here;

exports.up = function(db, cb) {
Expand Down
2 changes: 2 additions & 0 deletions models/Measurement.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

var hooks = require('./hooks.js');

module.exports = function(db, cb){
Expand Down
4 changes: 3 additions & 1 deletion models/Node.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

function lonlat(field) {
return function(val) {
if (val !== undefined) {
Expand All @@ -8,7 +10,7 @@ function lonlat(field) {
}

module.exports = function(db, cb){
var Node = db.define('Node', {
db.define('Node', {
name : { type: 'text', required: true }
, owner : { type: 'text', required: true }
, location : { type: 'point', required: false }
Expand Down
4 changes: 3 additions & 1 deletion models/NodeUpload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use strict";

var hooks = require('./hooks.js');

module.exports = function(db, cb){
var NodeUpload = db.define('NodeUpload', {
db.define('NodeUpload', {
node_name : { type: 'text', required: true }
, ts : { type: 'date', required: true }
, data : { type: 'binary', required: true }
Expand Down
2 changes: 2 additions & 0 deletions models/Upload.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

module.exports = function(db, cb){
var Upload = db.define('Upload', {
ts : { type: 'date', required: true }
Expand Down
4 changes: 3 additions & 1 deletion models/hooks.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"use strict";

var hstore = require('pg-hstore');

function hstore2json(field) {
return function() {
if (typeof this[field] === 'string')
this[field]= hstore.parse(this[field]);
this[field] = hstore.parse(this[field]);
};
}

Expand Down
2 changes: 2 additions & 0 deletions models/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

var orm = require('orm')
, transaction = require("orm-transaction")
, async = require('async')
Expand Down
8 changes: 5 additions & 3 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

var Payload = require('dustmap-payload')
, async = require('async')
, util = require('util')
, HAL = require('../lib/hal.js')
;

Expand Down Expand Up @@ -42,7 +43,7 @@ module.exports = function(app) {
}

async.each(models_to_save, function(obj, cb){
return obj.save(function(err, data){
return obj.save(function(err){
return cb( err ? err : null );
});
}, function(err){
Expand Down Expand Up @@ -196,7 +197,8 @@ module.exports = function(app) {
async.each(uploads, handleUpload, function(err){
if (err)
res.send(400, err);
res.send(node);

res.send(node);
});
});
});
Expand Down
2 changes: 2 additions & 0 deletions test/integration_tests/BEGIN.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

var util = require('util');
var exec = require('child_process').exec;
var path = require('path');
Expand Down
3 changes: 2 additions & 1 deletion test/integration_tests/webapp.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

var app = require('../../lib/express.js')
, request = require('supertest')(app)
, async = require('async')
;


Expand Down
40 changes: 0 additions & 40 deletions test/run.sh

This file was deleted.

0 comments on commit e4b7313

Please sign in to comment.