Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/phistrom/b2-remove-prefix
A CloudFlare Worker for removing the /file/bucket-name/ part of a B2 bucket domain
https://github.com/phistrom/b2-remove-prefix
Last synced: about 2 months ago
JSON representation
A CloudFlare Worker for removing the /file/bucket-name/ part of a B2 bucket domain
- Host: GitHub
- URL: https://github.com/phistrom/b2-remove-prefix
- Owner: phistrom
- License: unlicense
- Created: 2020-08-09T05:58:18.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-04-16T13:41:38.000Z (over 2 years ago)
- Last Synced: 2023-02-27T23:41:27.023Z (almost 2 years ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 15
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# B2 Remove Prefix Worker
A CloudFlare worker script that removes the `/file/{bucket-name}/` portion of
the URL when access a B2 Bucket.- Works with the free tier of CloudFlare and CloudFlare Workers
- It's still free egress from your B2 bucket
- No performance penalty, just prettier URLs for your B2 assets
- Doesn't expose the name of your B2 bucket in the URL## Why
If you followed [this guide to set up a CloudFlare domain in front of
Backblaze B2](https://help.backblaze.com/hc/en-us/articles/217666928-Using-Backblaze-B2-with-the-Cloudflare-CDN),
you may have been disappointed by the length of the URL.For instance, let's say you set up `i.example.com` as a proxied CNAME on
CloudFlare in front of `f001.backblazeb2.com`. Then for you to download a file
called `/test.txt` in the root of the bucket `example-bucket`, the URL would be
`https://i.example.com/file/example-bucket/test.txt`. By putting this Worker
script in front of it, your URL becomes a simple
`https://i.example.com/test.txt`.## License
[The Unlicense](https://unlicense.org/)## Installation
1. Use
[wrangler](https://developers.cloudflare.com/workers/tooling/wrangler/install)
to generate a new app
```sh
wrangler generate myapp https://github.com/phistrom/b2-remove-prefix
```
2. Overwrite the wrangler-generated `wrangler.toml` with a copy of
`wrangler.toml.example`.
3. Fill in `zone_id`, `account_id`, and `routes` fields as usual in
`wrangler.toml`
4. Also set the `B2_BUCKET_NAME` under `[vars]` in `wrangler.toml` to your B2
bucket name
5. Upload to the routes you specified with `wrangler publish`**Alternatively**, you could also just copy and paste the code from `index.js`
into the *Quick Edit* editor in your CloudFlare dashboard. Just be sure to also
set the `B2_BUCKET_NAME` and `CF_CACHE_TTL` environment variables for this
Worker by going into its settings.