Skip to content

Modernize the Worker code, Add Cloudflare KV integrations to white/blacklists, Update Readme, and more#37

Open
Jediweirdo wants to merge 22 commits intoZibri:masterfrom
Jediweirdo:master
Open

Modernize the Worker code, Add Cloudflare KV integrations to white/blacklists, Update Readme, and more#37
Jediweirdo wants to merge 22 commits intoZibri:masterfrom
Jediweirdo:master

Conversation

@Jediweirdo
Copy link

@Jediweirdo Jediweirdo commented Dec 25, 2025

Many, many things have changed:

Features:

  • Added customizable blacklists for origins and whitelists for queryable URLs
  • Added KV binding support to update all customizable variables (except pageHTML) without redeploying. Manual counterparts still exist and are easily editable if you don't think setting them up is worth the effort
  • Enabled HTML support for all pages
  • Added stylesheet injection via a top‑level styleSheet variable
  • Added debug flag to toggle console logging
  • Added optional redirect‑tracking via the x-cancel-redirect, x-request-url, and x-final-url headers (inspired by Update index.js #29)
  • Added documentation for:
    • Using KV Instances with the worker
    • TL;DR of features the worker can handle
    • All custom headers handled by the proxy
    • All variables intended to be editable in the worker (save for PAGE_HTML)
    • Known issues section
  • Added (commented) Cloudflare KV Instance boilerplate to wrangler.toml
  • Added usage page you can visit by going to "/usage" or "?uri"
  • Added config dictionary with the following editable settings:
    • DEBUG, which decides whether debug console messages are printed
    • ALLOW_NULL_ORIGINS, which decides if requests from null origins should be honored

Refactors:

  • Updated usage page to reflect markdown changes
  • Updated homepage to display new documentation page URL
  • Moved Demo URL disclaimer higher in README
  • Migrated worker from Service Worker boilerplate to ES Module Worker syntax
  • Consolidated (most) HTML elements into a single pageHTML dictionary
  • Reorganized blacklist logic into a self‑contained conditional block
  • Reorganized debug information printed on the homepage into an easier-to-read dictionary
  • Added hyperlinks to homepage
  • Added comments to everything I edited
  • Added error handling around fetch requests
  • Replaced depreciated String().substr() with String().substring()
  • Added last updated date/disclaimer to README

Bug Fixes:

Let me know if there are any bugs I accidentally left in. I don't make pull requests often, so I don't really know the social norms with these. Sorry in advance if I did something wrong

- Pass in a "x-cancel-redirect" custom header and set it to a true value to stop and log redirect behavior instead of automatically following
- Fixes compiling const error echoed in #39, Zibri#29, and Zibri#24
- Fixes bug that breaks URL-encoded URLs passed into the function by accidentally decoding them as addressed in Zibri#30

Later commits may expand on redirect tracking to add infinite loop protections
- Makes it so console.log() commands won't get saved to your dashboard, so you won't get charged for them. "Stolen" from Zibri#29
- Fix depreciated deployment command reference (Zibri#24)
- Fixes "Cloudflaer" Typo in deployment section (Zibri#31)
- Ensures that custom headers will be checked to have a non-null value when checking for the x-cancel-redirect bug
Refactors:
- moved all the HTML elements I could to one pageHTML dictionary at the top of the worker
- Flipped blacklist conditions so that blacklist code is self-contained in its own if statement
- Added some comments for the things I changed
- Refactored homepage debug information to print in a more legible/easily changeable way
- Added hyperlinks to the homepage

NEXT COMMIT: Refactor codebase from Service Worker Boilerplate to ES Module boilerplate

Features:
- HTML code is now supported for all pages
- Stylesheets can now be set in styleSheet variable at the top of the service worker
- Added debug flag that enables/disables console.log and console.warn text

Bug Fixes:
- Fixed bug that crashed the worker if a non-URL-encodable URL gets passed into the code
- Added try/catch to fetch request
Whoops, I let this bug through. The NEXT commit will be the one where the code gets refactored to support ES Module workers
Refactor:
- Migrated from Cloudflare Service Worker boilplate to Clouldflare ES Module Worker Syntax. You should be able to save when editing code inside of Clouldflare's quick editor instead of being forced to deploy

Bug fixes:
- Made filteredHeaders initialize as Header() instead of an untyped empty dictionary
Might be one more, but I forgot 

TODO in the future:
- Use secret vars (or something that allows variable assignment outside the workers editor) so you can add to the blacklist/whitelist from cloudflare's dashboard instead of the script itself
Features:
- Adds KV binding support to add/update all customizable variables (excpet for pageHTML) without redeploying the cloudflare instance
Refactor:
- Adds comments everywhere I screwed with things
- Consistently applies debug variable blocking to console.log stuff
- Adds back system-default ES Module boilerplate (so it doesn't delete all my comments again)

Known bugs:
- Internal 502 error if you successfully use the worker to proxy a URL inside of cloudflare's preview URL. Should work fine when deployed to production though
Just adds the necessary boilerplate to the Cloudflare TOML to work with the changes in the index.js. Note that these bindings are optional, and you can choose to manually update them in the index.js if you want to
Refactors:
- Got rid of autogenerated boilerplate because Cloudflare just generates them again and adds ugly numbers to the new boilerplate instead
- Made all (but one) console logs/warns only display if DEBUG is true
- Revisited all console logs/warnings and added more verbose language 
- Reformatted Fetch error response to be in line with the other error responses (save for the blacklisted page)

Bug Fixes:
- Fixed a bug where the URI wouldn't stop the null origin if the origin is passed in as a string called "null" instead of an actual null value
Bug Fixes:
- Added quotation marks to responseBody JSON keys in errors because I forgot them
- Adds feature overview section
- Adds documentation for using KV Instances with the worker
- Adds a table detailing every custom header the proxy handles
- Adds a known issues section that talks about the limitations of the proxy
- Moves Demo URL disclaimer closer to the top of the page since it seems important

Just need to go comment parts of the wrangler now and it'll be up to date
Since KV bindings aren't required, I commented them out so they don't interfere with deployment. Also added a comment explaining what the observability logs' enable button does

Writing this commit message was probably harder than the work done to the file itself
Refactor:
- Update Usage's HTML to be up-to-date with the readme's changes
- Reformatted the document via the "Format Document" button
- Made some comments more verbose and finished some accidently unfinished ones

Probably my last update before I pull request
Forgot to add an extended description to the last commit, so I'll also add that here alongside the changes made here:
LAST COMMIT:
Refactor:
- Added disclaimer that the project probably won't be updated past today
Bug fix:
- Fixed bad bold formatting in the KV Instance header, and reworded parts of said badly-formatted sentence
THIS COMMIT:
- Added a limitation to the known bugs section

If I can. I'll go back and readd that old description to that old commit as well
Refactors:
- Edits the usage HTML to match the readme, plus one small typo fix and one small disclaimer added to the end
- Edits a comment to be more verbose

This is probably going to be the last change to this file unless me or someone else decides to do add a content update or fix a bug

May or may not add the ability to whitelist and blacklist both URLs AND URL origins. Maybe.
Refactors:
- Adds disclaimer to the ALLOW_NULL_ORIGINS description in the the KV Instances header

Bug Fixes:
- Fix typo in the known issues header
Features:
- You can now customize the blacklist for origins and the whitelist for queryable URLs. When using Cloudflare Instance KVs, the keys control the URLs and the values control the Origins

Merry Christmas
Adds info to document the new blacklist/whitelist options introduced last commit. Will need to commit one more time to put these changes on the usage page in the index.js
Refactors:
- Updated usage page to reflect changes in the markdown
- Updated homepage to also show the page URL for the documentation page

And that's all she wrote. This will likely be the last commit from me before I make the pull request
@YJB-Gay
Copy link

YJB-Gay commented Dec 29, 2025

Full of AI slop, completely unhelpful

@Jediweirdo
Copy link
Author

Full of AI slop, completely unhelpful

If I vibe coded this, my multi day commit history would look completely different and be significantly smaller. Let me know if it's broken, not if you want to insult me and/or my coding skills

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants