Skip to content

Fix OGImage icon fetch on cloudflare #3253

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

Merged
merged 2 commits into from
May 21, 2025
Merged

Conversation

conico974
Copy link
Contributor

When a request for OG Image arrives for a custom domain, the requested favicon is requested from the same domain (i.e. https://thedomain.com/~gitbook/icon)
In Cloudflare, we were using a service binding, but by doing so, this bypass setting the x-gitbook-url header and thus the request will end up not being able to match getSiteUrlFromRequest

/**
* The URL of the GitBook content can be passed in 3 different ways (in order of priority):
* - The request has a `X-GitBook-URL` header:
* URL is taken from the header.
* - The request has a `X-Forwarded-Host` header:
* Host is taken from the header, pathname is taken from the request URL.
* - The request URL is matching `/url/:url`:
* URL is taken from the pathname.
*/
function getSiteURLFromRequest(request: NextRequest): URLWithMode | null {

We should be fine without the service binding since we set global_fetch_strictly_public compatibility flag

The icon will return a 404 and the OG Image Generation will fail with a 500

Should fix RND-7140

Copy link

linear bot commented May 21, 2025

Copy link

changeset-bot bot commented May 21, 2025

⚠️ No Changeset found

Latest commit: 863c196

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

argos-ci bot commented May 21, 2025

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
customers-v1 (Inspect) ✅ No changes detected - May 21, 2025, 1:01 PM
customers-v2 (Inspect) 👍 Changes approved 80 changed May 21, 2025, 1:18 PM
default (Inspect) ✅ No changes detected - May 21, 2025, 1:05 PM
v2-cloudflare (Inspect) ✅ No changes detected - May 21, 2025, 1:07 PM
v2-vercel (Inspect) ✅ No changes detected - May 21, 2025, 1:07 PM

Copy link
Member

@SamyPesse SamyPesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, the alternative was to set the header as well here, but I think it's better to unify between Vercel and Cloudflare on the way we fetch things here

@conico974
Copy link
Contributor Author

Makes sense, the alternative was to set the header as well here, but I think it's better to unify between Vercel and Cloudflare on the way we fetch things here

I've started doing exactly that at first, but there is not much benefits in doing so (technically it's slightly faster), it just complicate things.

@conico974 conico974 merged commit 19c20c0 into main May 21, 2025
21 checks passed
@conico974 conico974 deleted the cloudflare/fix-og-image branch May 21, 2025 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants