From fc06bf6ef38e85eae8dbbd47649807975bc71723 Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Tue, 8 Feb 2022 21:01:20 -0500 Subject: [PATCH] Account for uploads served through cloudflare when loading thumbnails and assets in the admin panel --- src/utils/phoenix-utils.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/utils/phoenix-utils.js b/src/utils/phoenix-utils.js index 818e4eb115..5ca00f548e 100644 --- a/src/utils/phoenix-utils.js +++ b/src/utils/phoenix-utils.js @@ -56,8 +56,14 @@ export function getReticulumFetchUrl(path, absolute = false, host = null, port = } export function getUploadsUrl(path, absolute = false, host = null, port = null) { - return configs.UPLOADS_HOST - ? `https://${configs.UPLOADS_HOST}${port ? `:${port}` : ""}${path}` + // If the Hubs Cloud stack is configured to use Cloudflare, we need to ignore the configured UPLOADS_HOST + // since reticulum will only serve uploads via the Cloudflare worker. BASE_ASSETS_PATH will have been + // correctly configured to use the Cloudflare worker, though we only need the hostname, + // not the full assets URL. + const isUsingCloudflare = configs.BASE_ASSETS_PATH.includes("workers.dev"); + const uploadsHost = isUsingCloudflare ? new URL(configs.BASE_ASSETS_PATH).hostname : configs.UPLOADS_HOST; + return uploadsHost + ? `https://${uploadsHost}${port ? `:${port}` : ""}${path}` : getReticulumFetchUrl(path, absolute, host, port); }