Deploying Static Sites using Cloudflare Pages
A few weeks ago, I converted my site to use Hugo. For the original Go server I created, I used a simple systemd service to serve the site:
# /etc/systemd/system/website.service
[Unit]
Description=website
Requires=network.target
After=multi-user.target
[Service]
Type=simple
WorkingDirectory=/home/<user>/website
ExecStart=/home/<user>/website/<server_executable>
User=root
Restart=always
RestartSec=5s
[Install]
WantedBy=multi-user.target
# /etc/systemd/system/website.socket
[Socket]
ListenStream=localhost:3000
[Install]
WantedBy=sockets.target
In my mind, I could use a similar setup to serve the Hugo version of the site. I thought it would be as simple as updating the path for the WorkingDirectory
and using hugo server
for the ExecStart
command. However, I ran into errors that I never encountered when running the Go server in a systemd service. While troubleshooting these errors, I stumbled upon Cloudflare Pages. Cloudflare Pages allows you to deploy web apps to the Cloudflare network. It supports a plethora of web frameworks including Hugo. Using Cloudflare Pages to serve the site came with a huge benefit: the site is now serverless and should never be down. Cloudflare simply pulls the code hosted on GitHub any time a new change is pushed. This allows me to push changes to the repo and see them update in (almost) realtime, giving me a minimal continuous integration and deployment setup.