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

use own cached templates release #4473

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

adhami3310
Copy link
Member

https://templates-releases.reflex.dev/ simply does the same request as https://api.github.com/repos/reflex-dev/templates/releases but doesn't have rate limiting, if the request fails in: https://templates-releases.reflex.dev/ it simply redirects to https://api.github.com/repos/reflex-dev/templates/releases in case something happens anyways, we have a try except here to use https://api.github.com/repos/reflex-dev/templates/releases as a fallback

Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

@adhami3310
Copy link
Member Author

const GITHUB_RELEASES = "https://api.github.com/repos/reflex-dev/templates/releases";

export default {
  async fetch(request, env, ctx) {
    const cache = await caches.default;

    const cacheResponse = await cache.match(GITHUB_RELEASES);
    if (cacheResponse !== undefined) {
      return cacheResponse;
    }

    const githubResponse = await fetch(GITHUB_RELEASES, {
      method: 'GET',
      headers: request.headers
    });

    const response = new Response(githubResponse.body, githubResponse);

    if (response.ok) {
      response.headers.append("Cache-Control", "s-maxage=" + (60 * 30).toString());
      await cache.put(GITHUB_RELEASES, response.clone());
      return response;
    }
    
    return Response.redirect(GITHUB_RELEASES, 301);
  },
};

@adhami3310
Copy link
Member Author

@masenf do we want to bring this in? the pro would be that we don't run into rate limiting for unauthenticated API requests, the disadvantage is that we might have an hour of delay and another component to maintain, it would also be helpful in case the API goes down but the releases are still accessible somehow

@masenf
Copy link
Collaborator

masenf commented Jan 7, 2025

do we want to bring this in?

not for 0.6.8

i like the idea, but before bringing it in i would want to see the service code in a repo somewhere that (hopefully) automatically deploys on push to main (at the very least we need deploy instructions that anyone can follow). Down the road it might make sense to cache the actual template archives as well, or maybe even push them to one of our r2/s3 buckets and not rely on github.

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