Replace your ugly CDN urls with something nice and custom. Built with Hono and Cloudflare.
- Hono - A small, simple, and ultra-fast web framework for Cloudflare Workers.
- React (
hono/jsx) - For building the user interface of the dashboard and login pages. - Tailwind CSS - For styling the dashboard and login pages.
- Cloudflare Workers - For deploying the application on the edge.
- Cloudflare KV - For storing user credentials and session tokens securely.
-
You have an ugly CDN url like
https://cdn.hackclub.com/019ce8b0-fb51-77e1-b026-755feddd406b/067A4083.webp, and you want to replace it with something likehttps://cdn.yourdomain.com/image.webp. -
You can set up a custom domain (e.g.,
cdn.yourdomain.com) to point to your Cloudflare Worker. -
You upload the file through the dashboard, and it gives you a nice URL like
https://cdn.yourdomain.com/cdn/:id_you_give_to_kitsune. -
When someone accesses that URL, Kitsune fetches the file from the original CDN and serves it to the user.
-
Clone the repository and navigate to the project directory.
-
Install the dependencies:
pnpm install
-
Create a
.dev.varsfile in the root of the project and add your Admin credentials:ADMIN_USERNAME=your_username ADMIN_PASSWORD=your_password # generate a hash of your password using `bun scripts/pwdgen.ts your_password` and use the hash here for better security AUTH_SECRET=some_random_secret_for_jwt
-
Create a KV namespace in your Cloudflare dashboard and add the binding to
wrangler.json:{ "kv_namespaces": [ { "binding": "db", "id": "your_kv_namespace_id" } ] } -
Setup file uploads,
src/lib/storage.tsis where the file upload logic exists. I'm usingcdn.hackclub.com, which is a CDN for teenage hackers (members of Hack Club). You can replace it with your own storage solution if you want. Just make sure to update the function to return the URL of the uploaded file. -
Add whatever credentials you need for the storage solution in the
.dev.varsfile and access them insrc/lib/storage.ts. -
Run the development server:
pnpm run dev # this is important, otherwise the cloudflare KV binding won't work -
To deploy, remember to put the .dev.vars values in the Cloudflare dashboard as environment variables, and then run:
pnpm run deploy
I have a sister project named imajesus.
It is a CLI tool that will make your images like 90% smaller using webp format. You can use it to compress your images before uploading them to Kitsune to save bandwidth and make them load faster.
-
Make kitsune compress the files before serving them to save bandwidth and make them load faster.
-
Suggest more features through issues!
