From 903713e7053a86b8b7cf5e550030320256d2baf4 Mon Sep 17 00:00:00 2001 From: Jared Donovan Date: Wed, 4 Jul 2018 06:02:46 +1000 Subject: [PATCH] WIP - Mixed content error for Issue #543 (#661) * Set trust proxy option on Express app. * Fix replacement of filePath for full screen and embed sketches. * Use const rather than let because is never reassigned. --- server/server.js | 2 ++ server/utils/previewGeneration.js | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/server/server.js b/server/server.js index d186ff4e..446326c5 100644 --- a/server/server.js +++ b/server/server.js @@ -45,6 +45,8 @@ if (process.env.NODE_ENV === 'development') { corsOriginsWhitelist.push(/localhost/); } +app.set('trust proxy', true); + // Enable Cross-Origin Resource Sharing (CORS) for all origins const corsMiddleware = cors({ credentials: true, diff --git a/server/utils/previewGeneration.js b/server/utils/previewGeneration.js index 61d1e5f5..a8f46e8d 100644 --- a/server/utils/previewGeneration.js +++ b/server/utils/previewGeneration.js @@ -29,7 +29,8 @@ function resolveLinksInString(content, files, projectId) { while (resolvedFilePath.startsWith('/')) { resolvedFilePath = resolvedFilePath.substr(1); } - newContent = newContent.replace(filePath, `/sketches/${projectId}/assets/${resolvedFilePath}`); + const replacement = `/sketches/${projectId}/assets/${resolvedFilePath}`; + newContent = newContent.replace(filePath, replacement); } } }