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
Open
Modernize the Worker code, Add Cloudflare KV integrations to white/blacklists, Update Readme, and more#37Jediweirdo wants to merge 22 commits intoZibri:masterfrom
Jediweirdo wants to merge 22 commits intoZibri:masterfrom
Conversation
- 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
- 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
|
Full of AI slop, completely unhelpful |
Author
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Many, many things have changed:
Features:
pageHTML) without redeploying. Manual counterparts still exist and are easily editable if you don't think setting them up is worth the effortstyleSheetvariablex-cancel-redirect,x-request-url, andx-final-urlheaders (inspired by Update index.js #29)PAGE_HTML)wrangler.tomlDEBUG, which decides whether debug console messages are printedALLOW_NULL_ORIGINS, which decides if requests from null origins should be honoredRefactors:
pageHTMLdictionaryBug Fixes:
"null"(string) origins bypassed theALLOW_NULL_ORIGINStoggleconst#25, Update index.js #29, feat: Allow reassignment of responseHeaders #34, Update index.js #35)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