Skip to content
Open
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
15 changes: 13 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
language: node_js
node_js:
- "0.10"
- "4"
compiler: clang-3.6
services:
- mongodb
- redis-server
addons:
apt:
sources:
- llvm-toolchain-precise-3.6
- ubuntu-toolchain-r-test
packages:
- clang-3.6
- g++-4.8
postgresql: "9.3"
sudo: true

before_script:
- openssl req -x509 -nodes -days 730 -newkey rsa:1024 -subj "/C=US/ST=MI/L=Detroit/O=Dis/CN=www.example.com" -keyout test/data/test-key.pem -out test/data/test-cert.pem
- psql -U postgres -c "create extension postgis"
- psql -c 'create database travis_ci_test;' -U postgres
- psql -d travis_ci_test -a -f test/data/features-db.sql
- psql -d travis_ci_test -a -f test/data/schema.sql

env:
global:
- CXX=clang-3.6
- secure: "TFbmH2rbf/t/1nMkpS09QcVWbI5AdWqQSDRmuwhIent88AxfdlY4mgtviDdtDZYDN4l/zwBf442ocmiImrCi7ZJsvLBpPtqHs0mDGzOCilVPxIM71Si3BSY3QWjPTG1WSSEHpsFUXz8pWr2hlAGFi6maUEo/KcDHf8xrcJuZHq8="
- secure: "AV7+wVMYrm4f6vu5NmFts8tARo7eDFDI8E3Rwb2swIlLJnAlc/YUcxZ7Mbiav+Ops7zcWNwgl5oYlNXwPj+AVdrQ9WnxVE+FgKDzkTC/4EDl2h/tqVEOkwVJ4D5EFt5NsF47GvnuTo3v7dTfpXUwXLPqIfgYDQIs3hx43f/kHFM="
- secure: "ETzchDuzsHT1PTpWdFJjlz/xydsZQkFPVcY6vcL62T6VZXSxZ2Ev15RBzpl5dM1Kr/8VlLH8MZiW33uXrnryAjtgsVDZmbF2ZarpRxk8bKTLf4UuqYh0aqnmzMivkGkMijgCVM82UgjNUYD0L/+B0Y+mEmXKiCHqBDLXw3oB5uQ="
Expand All @@ -33,4 +45,3 @@ env:
- TILESERVER_BASE=http://example.com
- TEST_SECURE_PORT=8888
- REDIS_URL=http://localhost:6379
sudo: false
34 changes: 18 additions & 16 deletions lib/controllers/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ exports.useCache = function useCache(req, res, next) {

if (cache.get(req.url) === etag) {
res.set('ETag', etag);
res.send(304);
res.sendStatus(304);

cacheStats.hits += 1;
}
Expand Down Expand Up @@ -101,7 +101,7 @@ exports.getById = function getById(req, response) {

// Require thie id
if (id === undefined || source === undefined) {
response.send(413);
response.sendStatus(413);
return;
}

Expand All @@ -119,7 +119,7 @@ exports.getById = function getById(req, response) {
if (error) {
console.log('postgres database error: ' + error.message);
console.log(error);
response.send(500);
response.sendStatus(500);
return;
}

Expand Down Expand Up @@ -160,11 +160,13 @@ exports.getById = function getById(req, response) {
.on('end', function (result) {
if (error) {
console.log(error);
response.send(500);
response.sendStatus(500);
} else {
// If there's no data, we want the client to check back.
// If there is data, we want the client to use its local cache for a
// while without hitting the network.
//
console.log("Got results in getById", result);
if (result.rows.length > 0) {
// 3600 seconds = 1 hour
response.set('Cache-Control', 'max-age=3600');
Expand Down Expand Up @@ -207,20 +209,20 @@ exports.get = function get(req, response) {
// Require a filter
if (bbox === undefined &&
(lon === undefined || lat === undefined)) {
response.send(413);
response.sendStatus(413);
return;
}

// Don't allow both filters at once
if (bbox !== undefined &&
(lon !== undefined || lat !== undefined)) {
response.send(400);
response.sendStatus(400);
return;
}

// Require either a type or a source
if (type === undefined && source === undefined) {
response.send(400);
response.sendStatus(400);
return;
}

Expand All @@ -231,7 +233,7 @@ exports.get = function get(req, response) {
coordString = bbox.split(',');

if (coordString.length !== 4) {
response.send(400);
response.sendStatus(400);
return;
}

Expand All @@ -242,7 +244,7 @@ exports.get = function get(req, response) {

// Make sure the conversion worked
if (isNaN(coords[i])) {
response.send(400);
response.sendStatus(400);
return;
}
}
Expand All @@ -256,7 +258,7 @@ exports.get = function get(req, response) {
lon = parseFloat(lon);

if (isNaN(lat) || isNaN(lon)) {
response.send(400);
response.sendStatus(400);
return;
}
geometry = 'POINT(' + lon + ' ' + lat + ')';
Expand Down Expand Up @@ -289,7 +291,7 @@ exports.get = function get(req, response) {
if (error) {
console.log('postgres database error: ' + error.message);
console.log(error);
response.send(500);
response.sendStatus(500);
return;
}

Expand Down Expand Up @@ -330,7 +332,7 @@ exports.get = function get(req, response) {
.on('end', function (result) {
if (error) {
console.log(error);
response.send(500);
response.sendStatus(500);
} else {
// If there's no data, we want the client to check back.
// If there is data, we want the client to use its local cache for a
Expand Down Expand Up @@ -362,7 +364,7 @@ exports.listSources = function listSources(req, res) {

if ((lat !== undefined && lon === undefined) ||
(lat === undefined && lon !== undefined)) {
res.send(400, {
res.status(400).send({
name: 'BadRequestError',
message: 'Must specify both lon and lat arguments.'
});
Expand Down Expand Up @@ -392,7 +394,7 @@ exports.listSources = function listSources(req, res) {
queryConfig = {
text: [
'SELECT DISTINCT source AS name, type FROM features',
'WHERE geom && ST_Expand(ST_SetSRID(ST_Point($1, $2),4326), .07)::geography',
'WHERE geom && ST_Expand(ST_SetSRID(ST_Point($1, $2),4326), .07)::geography'
].join('\n'),
values: [lon, lat],
name: 'featureNearbySourcesQuery'
Expand All @@ -403,7 +405,7 @@ exports.listSources = function listSources(req, res) {
if (error) {
console.log('postgres database error: ' + error.message);
console.log(error);
res.send(500);
res.sendStatus(500);
return;
}

Expand All @@ -426,7 +428,7 @@ exports.listSources = function listSources(req, res) {
.on('end', function (result) {
if (error) {
console.log(error);
res.send(500);
res.sendStatus(500);
} else {
res.send({
sources: result.rows
Expand Down
16 changes: 8 additions & 8 deletions lib/controllers/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports.get = function get(req, res) {
.exec(function (error, form) {
if (util.handleError(error)) { return; }
if (form === null) {
res.send(404);
res.sendStatus(404);
} else {
res.send({ form: form });
}
Expand All @@ -54,7 +54,7 @@ exports.post = function post(req, res) {
var surveyId = req.params.surveyId;

if (!data || !util.isArray(data)) {
res.send(400);
res.sendStatus(400);
return;
}

Expand Down Expand Up @@ -86,19 +86,19 @@ exports.post = function post(req, res) {
});

if (errors.length > 0) {
res.send(400, errors[0]);
res.status(400).send(errors[0]);
return;
}

Form.create(rawForms, function (error) {
if (error) {
res.send(500);
res.sendStatus(500);
return;
}
var output = Array.prototype.slice.call(arguments, 1).map(function (doc) {
return doc.toObject();
});
res.send(201, { forms: output });
res.status(201).send({ forms: output });
});
};

Expand All @@ -113,9 +113,9 @@ exports.put = function put(req, res) {
.exec(function (error, form) {
if (util.handleError(error)) { return; }
if (form === null) {
res.send(404);
res.sendStatus(404);
} else if (form.type !== modifiedForm.type) {
res.send(400, {
res.status(400).send({
name: 'SyntaxError',
message: 'You cannot change the form type'
});
Expand All @@ -133,7 +133,7 @@ exports.put = function put(req, res) {

form.save(function (error, doc) {
if (error) {
res.send(500);
res.sendStatus(500);
return;
}

Expand Down
14 changes: 7 additions & 7 deletions lib/controllers/orgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports.list = function list(req, res) {
if (user) {
// We currently only allow users to see their own orgs.
if (user !== req.user._id) {
res.send(403);
res.sendStatus(403);
return;
}
return exports.listForCurrentUser(req, res);
Expand All @@ -40,7 +40,7 @@ exports.get = function get(req, res) {
if (util.handleError(error, res)) { return; }

if (!org) {
res.send(404);
res.sendStatus(404);
return;
}
res.send({ org: org });
Expand All @@ -58,17 +58,17 @@ exports.post = function post(req, res) {
if (error) {
if (error.code === 11000) {
// Mongo duplicate key error
res.send(400, {
res.status(400).send({
type: 'OrgExistsError',
message: 'An organization with that name already exists'
});
} else {
console.log(error);
res.send(500);
res.sendStatus(500);
}
return;
}
res.send(201, { orgs: docs });
res.status(201).send({ orgs: docs });
});

};
Expand All @@ -82,13 +82,13 @@ exports.put = function put(req, res) {

// We didn't find an org with that ID.
if (!doc) {
res.send(404);
res.sendStatus(404);
return;
}

// Make sure the user is authorized.
if (doc.users.indexOf(req.user._id) === -1) {
res.send(403);
res.sendStatus(403);
return;
}

Expand Down
Loading