remove notLocalHost

This commit is contained in:
Danny Coates 2017-06-23 20:01:32 -07:00
parent 529c6d0fe7
commit 5cd44be83c
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
9 changed files with 26 additions and 35 deletions

View File

@ -49,7 +49,7 @@
"lint": "npm-run-all lint:*", "lint": "npm-run-all lint:*",
"lint:css": "stylelint 'public/*.css'", "lint:css": "stylelint 'public/*.css'",
"lint:js": "eslint .", "lint:js": "eslint .",
"start": "cross-env NODE_ENV=production node server/portal_server", "start": "node server/portal_server",
"test": "mocha", "test": "mocha",
"version": "node scripts/version" "version": "node scripts/version"
} }

View File

@ -3,7 +3,7 @@ const convict = require('convict');
const conf = convict({ const conf = convict({
s3_bucket: { s3_bucket: {
format: String, format: String,
default: 'localhost', default: '',
env: 'P2P_S3_BUCKET' env: 'P2P_S3_BUCKET'
}, },
redis_host: { redis_host: {
@ -19,18 +19,17 @@ const conf = convict({
}, },
analytics_id: { analytics_id: {
format: String, format: String,
default: 'UA-101393094-1', default: '',
env: 'GOOGLE_ANALYTICS_ID' env: 'GOOGLE_ANALYTICS_ID'
}, },
sentry_id: { sentry_id: {
format: String, format: String,
default: default: '',
'https://cdf9a4f43a584f759586af8ceb2194f2@sentry.prod.mozaws.net/238',
env: 'P2P_SENTRY_CLIENT' env: 'P2P_SENTRY_CLIENT'
}, },
sentry_dsn: { sentry_dsn: {
format: String, format: String,
default: 'localhost', default: '',
env: 'P2P_SENTRY_DSN' env: 'P2P_SENTRY_DSN'
}, },
env: { env: {
@ -45,8 +44,3 @@ conf.validate({ allowed: 'strict' });
const props = conf.getProperties(); const props = conf.getProperties();
module.exports = props; module.exports = props;
module.exports.notLocalHost =
props.env === 'production' &&
props.s3_bucket !== 'localhost' &&
props.sentry_dsn !== 'localhost';

View File

@ -1,12 +1,12 @@
const conf = require('./config.js'); const conf = require('./config.js');
const notLocalHost = conf.notLocalHost; const isProduction = conf.env === 'production'
const mozlog = require('mozlog')({ const mozlog = require('mozlog')({
app: 'FirefoxFileshare', app: 'FirefoxFileshare',
level: notLocalHost ? 'INFO' : 'verbose', level: isProduction ? 'INFO' : 'verbose',
fmt: notLocalHost ? 'heka' : 'pretty', fmt: isProduction ? 'heka' : 'pretty',
debug: !notLocalHost debug: !isProduction
}); });
module.exports = mozlog; module.exports = mozlog;

View File

@ -9,9 +9,7 @@ const conf = require('./config.js');
const storage = require('./storage.js'); const storage = require('./storage.js');
const Raven = require('raven'); const Raven = require('raven');
const notLocalHost = conf.notLocalHost; if (conf.sentry_dsn) {
if (notLocalHost) {
Raven.config(conf.sentry_dsn).install(); Raven.config(conf.sentry_dsn).install();
} }
@ -39,7 +37,6 @@ app.use(express.static(STATIC_PATH));
app.get('/', (req, res) => { app.get('/', (req, res) => {
res.render('index', { res.render('index', {
shouldRenderAnalytics: notLocalHost,
trackerId: conf.analytics_id, trackerId: conf.analytics_id,
dsn: conf.sentry_id dsn: conf.sentry_id
}); });
@ -64,7 +61,6 @@ app.get('/download/:id', (req, res) => {
res.render('download', { res.render('download', {
filename: filename, filename: filename,
filesize: bytes(contentLength), filesize: bytes(contentLength),
shouldRenderAnalytics: notLocalHost,
trackerId: conf.analytics_id, trackerId: conf.analytics_id,
dsn: conf.sentry_id dsn: conf.sentry_id
}); });
@ -93,7 +89,7 @@ app.get('/assets/download/:id', (req, res) => {
}); });
const file_stream = storage.get(id); const file_stream = storage.get(id);
file_stream.on(notLocalHost ? 'finish' : 'close', () => { file_stream.on('end', () => {
storage storage
.forceDelete(id) .forceDelete(id)
.then(err => { .then(err => {
@ -149,7 +145,7 @@ app.post('/upload/:id', (req, res, next) => {
req.busboy.on('file', (fieldname, file, filename) => { req.busboy.on('file', (fieldname, file, filename) => {
log.info('Uploading:', req.params.id); 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}/`; const url = `${protocol}://${req.get('host')}/download/${req.params.id}/`;
storage.set(req.params.id, file, filename, url).then(linkAndID => { storage.set(req.params.id, file, filename, url).then(linkAndID => {

View File

@ -6,8 +6,6 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
const crypto = require('crypto'); const crypto = require('crypto');
const notLocalHost = conf.notLocalHost;
const mozlog = require('./log.js'); const mozlog = require('./log.js');
const log = mozlog('portal.storage'); const log = mozlog('portal.storage');
@ -22,7 +20,7 @@ redis_client.on('error', err => {
log.info('Redis:', err); log.info('Redis:', err);
}); });
if (notLocalHost) { if (conf.s3_bucket) {
module.exports = { module.exports = {
filename: filename, filename: filename,
exists: exists, exists: exists,

View File

@ -3,9 +3,6 @@ const sinon = require('sinon');
const proxyquire = require('proxyquire'); const proxyquire = require('proxyquire');
const crypto = require('crypto'); const crypto = require('crypto');
const conf = require('../server/config.js');
conf.notLocalHost = true;
const redisStub = {}; const redisStub = {};
const exists = sinon.stub(); const exists = sinon.stub();
const hget = sinon.stub(); const hget = sinon.stub();
@ -52,7 +49,10 @@ const storage = proxyquire('../server/storage', {
'./log.js': function() { './log.js': function() {
return logStub; return logStub;
}, },
'aws-sdk': awsStub 'aws-sdk': awsStub,
'./config.js': {
s3_bucket: 'test'
}
}); });
describe('Testing Length using aws', function() { describe('Testing Length using aws', function() {

View File

@ -2,8 +2,7 @@ const assert = require('assert');
const sinon = require('sinon'); const sinon = require('sinon');
const proxyquire = require('proxyquire'); const proxyquire = require('proxyquire');
const conf = require('../server/config.js'); // const conf = require('../server/config.js');
conf.notLocalHost = false;
const redisStub = {}; const redisStub = {};
const exists = sinon.stub(); const exists = sinon.stub();

View File

@ -2,11 +2,13 @@
<html> <html>
<head> <head>
<title>Download your file</title> <title>Download your file</title>
{{> sentry dsn=dsn}} {{#if dsn}}
{{> sentry dsn=dsn}}
{{/if}}
<script src="/bundle.js"></script> <script src="/bundle.js"></script>
<link rel="stylesheet" href="https://code.cdn.mozilla.net/fonts/fira.css" /> <link rel="stylesheet" href="https://code.cdn.mozilla.net/fonts/fira.css" />
<link rel="stylesheet" type="text/css" href="/main.css" /> <link rel="stylesheet" type="text/css" href="/main.css" />
{{#if shouldRenderAnalytics}} {{#if trackerId}}
{{> analytics trackerId=trackerId}} {{> analytics trackerId=trackerId}}
{{/if}} {{/if}}
</head> </head>

View File

@ -2,11 +2,13 @@
<html> <html>
<head> <head>
<title>Firefox Fileshare</title> <title>Firefox Fileshare</title>
{{> sentry dsn=dsn}} {{#if dsn}}
{{> sentry dsn=dsn}}
{{/if}}
<script src="/bundle.js"></script> <script src="/bundle.js"></script>
<link rel="stylesheet" href="https://code.cdn.mozilla.net/fonts/fira.css" /> <link rel="stylesheet" href="https://code.cdn.mozilla.net/fonts/fira.css" />
<link rel="stylesheet" type="text/css" href="/main.css" /> <link rel="stylesheet" type="text/css" href="/main.css" />
{{#if shouldRenderAnalytics}} {{#if trackerId}}
{{> analytics trackerId=trackerId}} {{> analytics trackerId=trackerId}}
{{/if}} {{/if}}
</head> </head>