From 4c45d6217d0fc1b3031410d3f4983b36f9eeb687 Mon Sep 17 00:00:00 2001 From: timvisee Date: Fri, 7 May 2021 13:00:45 +0200 Subject: [PATCH] Properly derive base URL as configured in file upload logic Fixes https://github.com/timvisee/send/issues/29 --- server/routes/upload.js | 3 +-- server/routes/ws.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/server/routes/upload.js b/server/routes/upload.js index 7f16410a..023b83a9 100644 --- a/server/routes/upload.js +++ b/server/routes/upload.js @@ -28,8 +28,7 @@ module.exports = async function(req, res) { //this hasn't been updated to expiration time setting yet //if you want to fallback to this code add this await storage.set(newId, fileStream, meta, config.default_expire_seconds); - const protocol = config.env === 'production' ? 'https' : req.protocol; - const url = `${protocol}://${req.get('host')}/download/${newId}/`; + const url = `${config.deriveBaseUrl(req)}/download/${newId}/`; res.set('WWW-Authenticate', `send-v1 ${meta.nonce}`); res.json({ url, diff --git a/server/routes/ws.js b/server/routes/ws.js index b378f383..30be0248 100644 --- a/server/routes/ws.js +++ b/server/routes/ws.js @@ -65,8 +65,7 @@ module.exports = function(ws, req) { nonce: crypto.randomBytes(16).toString('base64') }; - const protocol = config.env === 'production' ? 'https' : req.protocol; - const url = `${protocol}://${req.get('host')}/download/${newId}/`; + const url = `${config.deriveBaseUrl(req)}/download/${newId}/`; ws.send( JSON.stringify({