Git Product home page Git Product logo

render's Introduction

Render

Proxies readonly requests to Cloudflare R2 via Cloudflare Workers.

Note: This worker might not conform to standards very well, but it should work in most cases... if you see a bug or something missing, please please please open an issue!

Features

  • Handles HEAD, GET, and OPTIONS requests
  • Forwards caching headers (etag, cache-control, expires, last-modified)
  • Forwards content headers (content-type, content-encoding, content-language, content-disposition)
  • Caches served files using the Cache API
  • Ranged requests (range, if-range, returns content-range)
  • Handles precondition headers (if-modified-since, if-unmodified-since, if-match, if-none-match)

Setup

Installing wrangler

npm i -g wrangler
wrangler login

Configuration

Create your R2 bucket(s) if you haven't already (replace bucket_name and preview_bucket_name appropriately):

wrangler r2 bucket create bucket_name # required
wrangler r2 bucket create preview_bucket_name # optional

You can also do this from the Cloudflare dashboard.

Edit wrangler.toml to have the correct bucket_name and optionally, preview_bucket_name (you can set it to bucket_name) if you're going to run this locally. You can do this from a fork, if using the GitHub Actions method.

You may edit CACHE_CONTROL to the default cache-control header or remove it entirely to fall back to nothing.

Deploying

Note: Due to how custom domains for workers work, you MUST use a route to take advantage of caching. Cloudflare may fix this soon. Also note that *.workers.dev domains do not cache responses. You MUST use a route to your own (sub)domain.

Method 1 (Local)

npm install
wrangler publish # or `npm run deploy`

Method 2 (GitHub Actions)

  1. Fork this repository
  2. Set the secrets CF_API_TOKEN (with Worker Scripts: Edit permissions) and CF_ACCOUNT_ID in the repo settings
  3. Enable workflows in the Actions tab
  4. Update wrangler.toml as needed (this will trigger the workflow)
  5. (Optionally) set the worker route in the Cloudflare dashboard to use the Cache API

Using as a package

You may use this worker's functionality as a package by installing and importing render2:

npm install render2

Usage:

import render from "render2";
render.fetch(req, env, ctx);

Development

Install deps:

npm install

To launch the development server:

npm run dev

render's People

Contributors

ben476 avatar cherry avatar zonimi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.