Skip to content

Conversation

@noghartt
Copy link
Contributor

Background

Fix #7036

This PR adds a new env for KV_BASE_URL which will let both CF CDN worker + API custom providers work on self-hosted setup for CDN.

Also, it adds a guarantee that it won't create any breaking change considering the old value.

Description

We changed these services:

  • package/services/cdn-worker: add a new env KV_BASE_URL + expose a new field on function createIsKeyValid to let the user pass any string value to be used by artifact handler.
  • Fix packages/services/server to, when using API provider for CDN, it let the user insert any KV, for compatibility with their setup (if on self-hosted).

Checklist

  • System configuration

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @noghartt, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the CDN worker and server configurations by introducing a new KV_BASE_URL environment variable. This allows self-hosted instances to specify a custom base URL for their Key-Value (KV) storage, improving flexibility for CDN providers (both Cloudflare worker and API-based). The changes are designed to be fully backward compatible, ensuring a smooth transition for existing deployments while expanding customization options for KV storage access.

Highlights

  • New KV Base URL Environment Variable: Introduced KV_STORAGE_BASE_URL for the CDN worker to allow custom KV storage endpoints.
  • Self-Hosted CDN Compatibility: Enables both Cloudflare CDN worker and API custom providers to work with self-hosted KV storage setups.
  • Backward Compatibility: Ensures that the changes do not introduce breaking changes for existing configurations.
  • Configurable Key Validation: The createIsKeyValid function now accepts an optional kvStorageBaseUrl to fetch schemas from a specified KV storage.
  • Server-Side Configuration: Added CDN_API_KV_BASE_URL and CDN_CF_KV_BASE_URL environment variables to the server for configuring KV base URLs for API and Cloudflare CDN providers, respectively.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a KV_BASE_URL environment variable for the CDN worker to allow custom KV storage endpoints, which is particularly useful for self-hosted setups. The changes span across the CDN worker and the server packages, adding the necessary configuration, type definitions, and logic to use the new variable while maintaining backward compatibility with a default URL.

My review has identified a critical syntax error that needs to be fixed, along with some medium-severity issues related to documentation accuracy, code maintainability (magic strings), and typos in comments. Overall, the changes are well-structured and address the intended feature.

const cacheKey = new Request(
[
'https://key-cache.graphql-hive.com',
args.kvStorageBaseUrl ?? 'https://key-cache.graphql-hive.com',
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The default KV storage base URL 'https://key-cache.graphql-hive.com' is hardcoded here and again on line 155. To avoid magic strings and ensure consistency, it's better to define this as a constant at the top of the file and reuse it in both places.

For example:

const DEFAULT_KV_STORAGE_BASE_URL = 'https://key-cache.graphql-hive.com';

Then you can use it here and on line 155.

| `S3_MIRROR_PUBLIC_URL` | No | The public URL of the S3, in case it differs from the `S3_ENDPOINT`. | `http://localhost:8083` |
| `CDN_API` | No | Whether the CDN exposed via API is enabled. | `1` (enabled) or `0` (disabled) |
| `CDN_API_BASE_URL` | No (Yes if `CDN_API` is set to `1`) | The public base url of the API service. | `http://localhost:8082` |
| `CDN_API_KV_BASE_URL` | No (**Optional** if `CDN_API` is set to `1`) | The base URL for the KV for OIDC related endpoints. | `https://key-cache.graphql-hive.com` |
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The description for CDN_API_KV_BASE_URL seems to be incorrect. It says it's for 'OIDC related endpoints', but based on the code changes, this URL is used for caching CDN access key validations. Please update the description to reflect its actual purpose.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is true, the endpoint is not related to OIDC, only for caching

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha, thought that there's some kind of relationship with the endpoint per se here.

| `COMMERCE_ENDPOINT` | **Yes** | The endpoint of the commerce service. | `http://127.0.0.1:4012` |
| `CDN_CF` | No | Whether the CDN is enabled. | `1` (enabled) or `0` (disabled) |
| `CDN_CF_BASE_URL` | No (**Yes** if `CDN` is `1`) | The base URL of the cdn. | `https://cdn.graphql-hive.com` |
| `CDN_CF_KV_BASE_URL` | No (**Optional** if `CDN` is `1`) | The base URL for the KV using CloudFlare provider | `https://key-cache.graphql-hive.com` |
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The description for CDN_CF_KV_BASE_URL could be more specific. It's used for caching CDN access key validations. A more descriptive text would be helpful for users, for example: 'The base URL for the key-value store used for CDN access key validation caching when using the Cloudflare provider.'

Copy link
Contributor

Choose a reason for hiding this comment

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

This is true, it could be improved.

noghartt and others added 3 commits October 30, 2025 15:55
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@n1ru4l
Copy link
Contributor

n1ru4l commented Oct 31, 2025

As a general question: what are the implications if you deploy this to your own cloudflare, with https://key-cache.graphql-hive.com hardcoded?

@noghartt
Copy link
Contributor Author

As a general question: what are the implications if you deploy this to your own cloudflare, with https://key-cache.graphql-hive.com hardcoded?

From the tests I did in my self-hosted solution, it didn't work. So what I did was changing it in a similar way I did on this PR (without the conditional).

But not sure if you guys are using this URL for the caching yet or there's something new, I left it as the fallback, just in case to avoid any breaking change (even because there's a usage of it on the server).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Self-hosted CDN worker should have an env for KV cache URL (CloudFlare R2)

2 participants