Skip to content
This repository was archived by the owner on May 22, 2021. It is now read-only.

Commit

Permalink
Merge pull request #130 from mozilla/sentry-server
Browse files Browse the repository at this point in the history
added sentry to server code
  • Loading branch information
dannycoates authored Jun 23, 2017
2 parents 2691dfc + 525c151 commit 7b713a6
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 8 deletions.
32 changes: 32 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"helmet": "^3.6.1",
"jquery": "^3.2.1",
"mozlog": "^2.1.1",
"raven": "^2.1.0",
"raven-js": "^3.16.0",
"redis": "^2.7.1",
"uglify-es": "3.0.19"
Expand Down
8 changes: 7 additions & 1 deletion server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const conf = convict({
sentry_id: {
format: String,
default: 'https://cdf9a4f43a584f759586af8ceb2194f2@sentry.prod.mozaws.net/238',
env: 'P2P_SENTRY_CLIENT'
},
sentry_dsn: {
format: String,
default: 'localhost',
env: 'P2P_SENTRY_DSN'
},
env: {
Expand All @@ -42,4 +47,5 @@ module.exports = props;

module.exports.notLocalHost =
props.env === 'production' &&
props.s3_bucket !== 'localhost';
props.s3_bucket !== 'localhost' &&
props.sentry_dsn !== 'localhost';
11 changes: 8 additions & 3 deletions server/portal_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ const helmet = require('helmet');
const bytes = require('bytes');
const conf = require('./config.js');
const storage = require('./storage.js');
const Raven = require('raven');

const notLocalHost = conf.notLocalHost;

if (notLocalHost) {
Raven.config(conf.sentry_dsn).install();
}

const mozlog = require('./log.js');

const log = mozlog('portal.server');
Expand Down Expand Up @@ -38,9 +43,9 @@ app.get('/', (req, res) => {

app.get('/exists/:id', (req, res) => {
const id = req.params.id;
storage.exists(id).then(doesExist => {
res.sendStatus(doesExist ? 200 : 404);
});
storage.exists(id).then(() => {
res.sendStatus(200);
}).catch(err => res.sendStatus(404));
});

app.get('/download/:id', (req, res) => {
Expand Down
8 changes: 6 additions & 2 deletions server/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function filename(id) {
if (!err) {
resolve(reply);
} else {
reject();
reject(err);
}
});
});
Expand All @@ -58,7 +58,11 @@ function filename(id) {
function exists(id) {
return new Promise((resolve, reject) => {
redis_client.exists(id, (rediserr, reply) => {
resolve(reply === 1);
if (reply === 1 && !rediserr) {
resolve();
} else {
reject(rediserr);
}
});
});
}
Expand Down
8 changes: 6 additions & 2 deletions test/local.storage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ const storage = proxyquire('../server/storage', {
describe('Testing Exists from local filesystem', function() {
it('Exists returns true when file exists', function() {
exists.callsArgWith(1, null, 1);
return storage.exists('test').then(reply => assert(reply));
return storage.exists('test')
.then(() => assert(1))
.catch(err => assert.fail())
});

it('Exists returns false when file does not exist', function() {
exists.callsArgWith(1, null, 0);
return storage.exists('test').then(reply => assert(!reply));
return storage.exists('test')
.then(() => assert.fail())
.catch(err => assert(1))
});
});

Expand Down

0 comments on commit 7b713a6

Please sign in to comment.