Code Monkey home page Code Monkey logo

multi-render's Introduction

multi-render

A Cloudflare Workers project showcasing how to have multiple kotx/render instances in a single Worker, allowing R2 buckets and settings to vary by domain within the same Worker.

Setup

  1. Clone the repository.
  2. Install dependencies: npm install
  3. Edit wrangler.toml to change default settings and specify domains and buckets. This repository is setup for my usage so remove my buckets you won't use.
  4. Open index.ts, add the buckets to the Env type following the example, and add config for them below.

E.g.

wrangler.toml

routes = [
  { pattern = "mybucket.example.com", custom_domain = true },
]

[[r2_buckets]]
binding = "MY_BUCKET"
bucket_name = "mybucket"
preview_bucket_name = "mybucket"

index.ts

interface Env {
	R2_BUCKET: R2Bucket,
	ALLOWED_ORIGINS?: string,
	CACHE_CONTROL?: string,
	PATH_PREFIX?: string
	INDEX_FILE?: string
	NOTFOUND_FILE?: string
	DIRECTORY_LISTING?: boolean
	HIDE_HIDDEN_FILES?: boolean
	DIRECTORY_CACHE_CONTROL?: string

	// put extra buckets here
	MY_BUCKET: R2Bucket
}
		const config: { [id: string]: RenderEnv; } = {
			"mybucket.example.com": {
				R2_BUCKET: env.MY_BUCKET,
				DIRECTORY_LISTING: true,
				INDEX_FILE: 'index_alt.html',
				ALLOWED_ORIGINS: "my-other-cool-site.example.com"
			},

Once done, npm run deploy and enjoy.

multi-render's People

Contributors

dependabot[bot] avatar erisa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.