johnpoint

johnpoint

(。・∀・)ノ゙嗨
github

Migrating a blog to Cloudflare - Pitfalls and Challenges

Long time no see. Since the beginning of the new year, I have been busy with my graduation project and finding a new job for my internship. I haven't had time to document some of the tinkering I've done as blog posts. Recently, during a break from working on my graduation project, I finally optimized my blog and decided to write a blog post about it.

In the past, my blog was deployed using multiple nodes and traffic routing was done through dnspod's regional resolution to direct traffic to the closest node in order to ensure fast blog access. Initially, the synchronization of blog files between multiple nodes was done through scheduled tasks from GitHub, but later I switched to using syncthing for synchronization. This method may seem a bit silly, but it has consistently ensured smooth access to my blog over the past two years.

Recently, while browsing through sukkad's blog, I learned about Cloudflare Workers, which can be used in conjunction with KV storage to deploy static websites. So I decided to first deploy my self-hosted image service (which is an HTTP service that stores images) on Cloudflare. The speed and latency of the service were quite good, so I decided to completely migrate my blog to Cloudflare.

This way, I can ensure high reliability and relatively good response speed for my blog without actively tinkering with it.

404 Page Issue#

In the worker-site/index.js file, there is a logic that controls returning /404.html when the file cannot be obtained from the URL. However, after deploying it, I noticed something was wrong. The 404 page was displayed as the source code directly, without being rendered by the browser.

By using the F12 method and checking the network response, I found out that the response data was missing a header specifying the response data format.

To fix this issue, you just need to add the appropriate header when returning the response. You can refer to the pull request I submitted for the code modifications.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.