From 1c67eea2f0f313801c49b44038ef0a8893c57b89 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Wed, 7 Jun 2017 16:46:48 -0700 Subject: [PATCH 1/3] use redis host from config --- server/storage.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/storage.js b/server/storage.js index 2b72cb9c..28b1c8ba 100644 --- a/server/storage.js +++ b/server/storage.js @@ -8,7 +8,9 @@ const fetch = require('node-fetch'); const crypto = require('crypto'); const redis = require('redis'); -const redis_client = redis.createClient(); +const redis_client = redis.createClient({ + host: conf.redis_host +}); redis_client.on('error', err => { console.log(err); From 82b71b2af7e7f942d793e5fba6dc3c8b6a394b5b Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Wed, 7 Jun 2017 16:55:11 -0700 Subject: [PATCH 2/3] hardcode prod to https urls --- server/portal_server.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/portal_server.js b/server/portal_server.js index 31329320..3029f5d4 100644 --- a/server/portal_server.js +++ b/server/portal_server.js @@ -115,7 +115,8 @@ app.post('/upload/:id', (req, res, next) => { req.pipe(req.busboy); req.busboy.on('file', (fieldname, file, filename) => { console.log('Uploading: ' + filename); - let url = `${req.protocol}://${req.get('host')}/download/${req.params.id}/`; + const protocol = conf.env === 'development' ? req.protocol : 'https'; + let url = `${protocol}://${req.get('host')}/download/${req.params.id}/`; storage.set(req.params.id, file, filename, url).then(linkAndID => { res.json(linkAndID); From 24abf669b02a6bffee5318c76a6301453cefde22 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Wed, 7 Jun 2017 17:03:03 -0700 Subject: [PATCH 3/3] stream download after headers --- server/portal_server.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/server/portal_server.js b/server/portal_server.js index 3029f5d4..5b2585f2 100644 --- a/server/portal_server.js +++ b/server/portal_server.js @@ -63,19 +63,18 @@ app.get('/assets/download/:id', (req, res) => { 'Content-Type': 'application/octet-stream', 'Content-Length': contentLength }); - }); + let file_stream = storage.get(id); - let file_stream = storage.get(id); - - file_stream.on(notLocalHost ? 'finish' : 'close', () => { - storage.forceDelete(id).then(err => { - if (!err) { - console.log('Deleted.'); - } + file_stream.on(notLocalHost ? 'finish' : 'close', () => { + storage.forceDelete(id).then(err => { + if (!err) { + console.log('Deleted.'); + } + }); }); - }); - file_stream.pipe(res); + file_stream.pipe(res); + }); }) .catch(err => { res.sendStatus(404);