Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for cloudflare when loading admin panel assets #5100

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/utils/phoenix-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down