Database Scare and Cloudflare Error Page Beautification
The complete code for this project is available in the Chinese version of this article. You’re welcome to visit www.exyone.me to access the code.
Since migrating my blog from a cloud server to a self-hosted environment, I couldn’t resist the urge to tinker, and problems kept popping up out of nowhere.
First came the scare of nearly losing my database. Fortunately, I had backed it up in the BT Panel before migration. Otherwise, my blog posts, comments, and carefully adjusted configurations might have all gone down the drain. Although it ended well, the tension of “data is life” still gives me chills when I think back on it. However, learning from mistakes, I later discovered that BT Panel’s database backup isn’t entirely reliable. I recommend using Halo’s built-in backup function for regular full backups. Backing up only the database can easily lead to the awkward situation of “data recovered, but files gone.” I didn’t use many plugins, so I gradually reinstalled them all later.
Just as I had settled the database, the internal network penetration node suddenly went down. The Japan node (jp.5.frp.one) went completely offline, and the Cloudflare Worker reverse proxy kept throwing errors. My blog instantly turned into several strings of JSON error codes. Both the main domain and backup domain pointed to this penetration tunnel, so naturally, they both went down as well. Talk about adding insult to injury - my blog “died twice.”
Fortunately, after some emergency rescue, the blog is now fully restored. To completely avoid both nodes having problems simultaneously, I specifically bound the backup domain exyone.us.kg to a Lithuania node (ltw.frp.one) as a reliable fallback. This avoids the dilemma of “one node goes offline, two domains show errors.”
Taking advantage of this tinkering, I upgraded the Cloudflare Worker reverse proxy code, focusing on beautifying the error page. Previously, errors would just throw out a cold JSON or Cloudflare’s default error page, which looked completely impersonal. Now I’ve created an error page with a “winter snowstorm” atmosphere using pure HTML5: deep blue gradient background, gently falling snowflake animation, frosted glass texture cards, mountain silhouette decorations, and a 5-second auto-redirect to the backup domain function. It adds a bit of fun, so visitors won’t be too disappointed when they see it.
Below is the complete new Worker code (with optimized configuration, error handling, and beautification logic). I recommend changing key configurations like TARGET_URL and REDIRECT_DOMAIN to Cloudflare environment variables to avoid hardcoding:
Code Update Notes
Security: Cleaned sensitive headers, added timeout protection (15 seconds), and processed Location redirects with relative paths.
Maintainability: All key configurations use environment variables, making it easy to switch nodes later, avoiding the “hardcoding” problem of the old version.