This is a pastebin that can be deployed on Cloudflare workers. Try it on shz.al.
Philosophy: effortless deployment, friendly CLI usage, rich functionality.
Features:
- Share your paste with as short as 4 characters
- Customize the paste URL
- Update and delete your paste as you want
- Expire your paste after a period of time
- Syntax highlighting powered by PrismJS
- Display markdown file as HTML
- Used as a URL shortener
- Customize returned mimetype
-
You can post, update, delete your paste directly on the website (such as shz.al).
-
It also provides a convenient HTTP API to use. See API reference for details. You can easily call API via command line (using
curl
or similar tools). -
pb is a bash script to make it easier to use on command line.
- If deployed on the Cloudflare Worker free-tier plan, the service allows at most 100,000 reads and 1000 writes, 1000 deletes per day.
- Due to the size limit of Cloudflare KV storage, the size of each paste is bounded under 25 MiB.
You are free to deploy the pastebin on your own domain if you host your domain on Cloudflare.
Requirements:
- *nix environment with bash and basic cli programs. Try cygwin, WSL or something if using Windows.
- GNU
make
andyarn
Step 1. Create a KV namespaces on Cloudflare workers dashboard and remember its namespace ID.
Step 2. Clone the repository and enter the directory. Run yarn
to install dependencies.
Step 3. Modify entries in wrangler.toml
according to your own account information (routes, kv namespace id are what you need to modify, do not touch the binding name).
Note
Ensure that the domain in your routes configuration is hosted on your Cloudflare account.
Step 4. Modify the contents in config.json
: BASE_URL
is the URL of your site (no trailing slash); FAVICON
is the URL to the favicon you want to use on your site.
Step 5. Run make deploy
and enjoy.
The command make deploy
does the following things:
- generate the HTML file for frontend pages.
- Upload these HTML file to your KV store.
- Build and upload the JavaScript file for the Cloudflare worker.
If you want a private deployment (only you can upload paste, but everyone can read the paste), add the following entry to your config.json
(other configurations also contained in the outmost brace):
{
"basicAuth": {
"enabled": true,
"passwd": {
"admin1": "this-is-passwd-1",
"admin2": "this-is-passwd-2"
}
}
}
Now every access to PUT or POST request, and every access to the index page, requires an HTTP basic auth with the user-password pair listed above. For example:
$ curl example-pb.com
HTTP basic auth is required
$ curl -Fc=@/path/to/file example-pb.com
HTTP basic auth is required
$ curl -u admin1:wrong-passwd -Fc=@/path/to/file example-pb.com
Error 401: incorrect passwd for basic auth
$ curl -u admin1:this-is-passwd-1 -Fc=@/path/to/file example-pb.com
{
"url": "https://example-pb.com/YCDX",
"suggestUrl": null,
"admin": "https://example-pb.com/YCDX:Sij23HwbMjeZwKznY3K5trG8",
"isPrivate": false
}