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

remove notLocalHost #138

Merged
merged 1 commit into from
Jun 24, 2017
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"lint": "npm-run-all lint:*",
"lint:css": "stylelint 'public/*.css'",
"lint:js": "eslint .",
"start": "cross-env NODE_ENV=production node server/portal_server",
"start": "node server/portal_server",
"test": "mocha",
"version": "node scripts/version"
}
Expand Down
14 changes: 4 additions & 10 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const convict = require('convict');
const conf = convict({
s3_bucket: {
format: String,
default: 'localhost',
default: '',
env: 'P2P_S3_BUCKET'
},
redis_host: {
Expand All @@ -19,18 +19,17 @@ const conf = convict({
},
analytics_id: {
format: String,
default: 'UA-101393094-1',
default: '',
env: 'GOOGLE_ANALYTICS_ID'
},
sentry_id: {
format: String,
default:
'https://cdf9a4f43a584f759586af8ceb2194f2@sentry.prod.mozaws.net/238',
default: '',
env: 'P2P_SENTRY_CLIENT'
},
sentry_dsn: {
format: String,
default: 'localhost',
default: '',
env: 'P2P_SENTRY_DSN'
},
env: {
Expand All @@ -45,8 +44,3 @@ conf.validate({ allowed: 'strict' });

const props = conf.getProperties();
module.exports = props;

module.exports.notLocalHost =
props.env === 'production' &&
props.s3_bucket !== 'localhost' &&
props.sentry_dsn !== 'localhost';
8 changes: 4 additions & 4 deletions server/log.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const conf = require('./config.js');

const notLocalHost = conf.notLocalHost;
const isProduction = conf.env === 'production'

const mozlog = require('mozlog')({
app: 'FirefoxFileshare',
level: notLocalHost ? 'INFO' : 'verbose',
fmt: notLocalHost ? 'heka' : 'pretty',
debug: !notLocalHost
level: isProduction ? 'INFO' : 'verbose',
fmt: isProduction ? 'heka' : 'pretty',
debug: !isProduction
});

module.exports = mozlog;
10 changes: 3 additions & 7 deletions server/portal_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ const conf = require('./config.js');
const storage = require('./storage.js');
const Raven = require('raven');

const notLocalHost = conf.notLocalHost;

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

Expand Down Expand Up @@ -39,7 +37,6 @@ app.use(express.static(STATIC_PATH));

app.get('/', (req, res) => {
res.render('index', {
shouldRenderAnalytics: notLocalHost,
trackerId: conf.analytics_id,
dsn: conf.sentry_id
});
Expand All @@ -64,7 +61,6 @@ app.get('/download/:id', (req, res) => {
res.render('download', {
filename: filename,
filesize: bytes(contentLength),
shouldRenderAnalytics: notLocalHost,
trackerId: conf.analytics_id,
dsn: conf.sentry_id
});
Expand Down Expand Up @@ -93,7 +89,7 @@ app.get('/assets/download/:id', (req, res) => {
});
const file_stream = storage.get(id);

file_stream.on(notLocalHost ? 'finish' : 'close', () => {
file_stream.on('end', () => {
storage
.forceDelete(id)
.then(err => {
Expand Down Expand Up @@ -149,7 +145,7 @@ app.post('/upload/:id', (req, res, next) => {
req.busboy.on('file', (fieldname, file, filename) => {
log.info('Uploading:', req.params.id);

const protocol = notLocalHost ? 'https' : req.protocol;
const protocol = conf.env === 'production' ? 'https' : req.protocol;
const url = `${protocol}://${req.get('host')}/download/${req.params.id}/`;

storage.set(req.params.id, file, filename, url).then(linkAndID => {
Expand Down
4 changes: 1 addition & 3 deletions server/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const fs = require('fs');
const path = require('path');
const crypto = require('crypto');

const notLocalHost = conf.notLocalHost;

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

const log = mozlog('portal.storage');
Expand All @@ -22,7 +20,7 @@ redis_client.on('error', err => {
log.info('Redis:', err);
});

if (notLocalHost) {
if (conf.s3_bucket) {
module.exports = {
filename: filename,
exists: exists,
Expand Down
8 changes: 4 additions & 4 deletions test/aws.storage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ const sinon = require('sinon');
const proxyquire = require('proxyquire');
const crypto = require('crypto');

const conf = require('../server/config.js');
conf.notLocalHost = true;

const redisStub = {};
const exists = sinon.stub();
const hget = sinon.stub();
Expand Down Expand Up @@ -52,7 +49,10 @@ const storage = proxyquire('../server/storage', {
'./log.js': function() {
return logStub;
},
'aws-sdk': awsStub
'aws-sdk': awsStub,
'./config.js': {
s3_bucket: 'test'
}
});

describe('Testing Length using aws', function() {
Expand Down
3 changes: 1 addition & 2 deletions test/local.storage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ const assert = require('assert');
const sinon = require('sinon');
const proxyquire = require('proxyquire');

const conf = require('../server/config.js');
conf.notLocalHost = false;
// const conf = require('../server/config.js');

const redisStub = {};
const exists = sinon.stub();
Expand Down
6 changes: 4 additions & 2 deletions views/download.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
<html>
<head>
<title>Download your file</title>
{{> sentry dsn=dsn}}
{{#if dsn}}
{{> sentry dsn=dsn}}
{{/if}}
<script src="/bundle.js"></script>
<link rel="stylesheet" href="https://code.cdn.mozilla.net/fonts/fira.css" />
<link rel="stylesheet" type="text/css" href="/main.css" />
{{#if shouldRenderAnalytics}}
{{#if trackerId}}
{{> analytics trackerId=trackerId}}
{{/if}}
</head>
Expand Down
6 changes: 4 additions & 2 deletions views/index.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
<html>
<head>
<title>Firefox Fileshare</title>
{{> sentry dsn=dsn}}
{{#if dsn}}
{{> sentry dsn=dsn}}
{{/if}}
<script src="/bundle.js"></script>
<link rel="stylesheet" href="https://code.cdn.mozilla.net/fonts/fira.css" />
<link rel="stylesheet" type="text/css" href="/main.css" />
{{#if shouldRenderAnalytics}}
{{#if trackerId}}
{{> analytics trackerId=trackerId}}
{{/if}}
</head>
Expand Down