Giter Site home page Giter Site logo

ryanccn / vendflare Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 0.0 715 KB

Vencord backend on Cloudflare Workers

License: GNU Affero General Public License v3.0

JavaScript 0.58% TypeScript 99.42%
cloudflare cloudflare-kv cloudflare-workers discord sync typescript vencord durable-objects

vendflare's Introduction

Vendflare

A Vencord backend/cloud/API running on Cloudflare Workers with Workers KV or Durable Objects.

The official implementation uses monolithic Go and Redis.

Getting started

Deploy this worker on Cloudflare using wrangler.

Change the bindings of the KV in wrangler.toml to the KV IDs on your own account. You could also use Durable Objects, which require subscribing to a paid plan on Cloudflare Workers; see Storage backends for more information.

An example of how you would do this:

$ git clone https://github.com/ryanccn/vendflare.git
$ cd vendflare
$ pnpm install --frozen-lockfile
$ pnpm run deploy

Then register a Discord application and set the OAuth client ID and secret as environment variables on your worker as DISCORD_CLIENT_ID and DISCORD_CLIENT_SECRET, respectively.

You can set ALLOWED_USERS as a comma-separated list of user IDs to only allow some users to use this instance.

You can also set a SIZE_LIMIT to limit the size of the configuration (so that people don't use it as a cloud drive).

Set ROOT_REDIRECT for the URL to redirect to on the root URL.

Storage backends

Vendflare's unified storage interface supports Workers KV and Durable Objects.

KV is often faster to retrieve and is free for a fair amount of usage (more than enough for Vendflare), but it is eventually consistent, meaning that changes take a minute or so to propagate to Cloudflare datacenters around the world. This may pose issues with synchronization.

Durable Objects are strongly consistent, located only in one datacenter location closest to the user who triggered the creation of the Object and providing a storage API designed for consistency. However, using it requires subscribing to the Cloudflare Workers paid plan.

It is recommended to try KV first. If major synchronization issues arise (which is a small possibility), switch to Durable Objects. Data is not shared between the storage backends.

When using KV, use wrangler.toml to bind KV to the KV on your Cloudflare account.

When using Durable Objects, also use wrangler.toml to bind USER_DATA to the UserData class exported by the worker.

Vendflare will automatically pick up whichever is defined (Durable Objects > KV) and use it for storage. If you specify a STORAGE_BACKEND variable of either "do", "kv", it will only try to use that backend.

Builds

By default, the deployed Cloudflare worker uses the dist/worker.js build, which supports KV and Durable Objects. It also uses the default Hono preset, which includes a more performant but larger bundle size router (recommended). The tiny preset includes a much smaller but less performant router.

One recommended optimization is to use the build that only supports the storage backend that you are actually using.

Build KV Durable Objects Hono preset Size
dist/worker.js Default ~40 kB
dist/worker.kv.js Default ~38 kB
dist/worker.do.js Default ~39 kB
dist/worker.tiny.js Tiny ~32 kB
dist/worker.kv.tiny.js Tiny ~30 kB
dist/worker.do.tiny.js Tiny ~32 kB

You can change what build you use by going to wrangler.toml and editing the main field to the path of the build that you want to use.

Testing

Tests are powered by Vitest. Tests utilize an in-memory temporary KV store that emulates Cloudflare Workers' actual runtime KV binding.

License

GNU AGPL v3

vendflare's People

Contributors

dependabot[bot] avatar renovate[bot] avatar ryanccn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vendflare's Issues

Work on other platforms

Sort of defeats the naming of this project, but: being able to self host, at the very least, would be nice.

Option 1: Dockerizing workerd

Various incompatibilities with Alpine Linux base image, was unable to get workerd running / compiling but could be done with more work(?).

Benefits would be keeping all the current syntax and APIs.

Option 2: Making the codebase platform-agnostic

Building the code using esbuild with different defines should be fine for dead code elimination and smart bundling.

Would most likely require moving away from Hono's ctx.env, since Node.js doesn't seem to support it very well. Would require lots of compatibility layers to interoperate between different platforms.

Durable Objects

Cloudflare KV is eventually consistent, which makes it pretty™ bad™ for sync services.

Durable Objects are strongly consistent.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Other Branches

These updates are pending. To force PRs open, click the checkbox below.

  • chore(deps): update dependency eslint to v8.44.0

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/deploy.yml
  • actions/checkout v3
  • actions/setup-node v3
  • pnpm/action-setup v2
.github/workflows/lint.yml
  • actions/checkout v3
  • pnpm/action-setup v2
  • actions/setup-node v3
  • github/codeql-action v2
npm
package.json
  • hono ^3.2.7
  • @cloudflare/workers-types ^4.20230518.0
  • @microsoft/eslint-formatter-sarif ^3.0.0
  • @typescript-eslint/eslint-plugin ^5.60.1
  • @typescript-eslint/parser ^5.60.1
  • eslint ^8.43.0
  • prettier ^2.8.8
  • typescript ^5.1.6
  • wrangler ^3.1.1
  • pnpm 8.6.3

  • Check this box to trigger a request for Renovate to run again on this repository

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.