{"id":4427,"date":"2022-10-20T17:00:41","date_gmt":"2022-10-20T21:00:41","guid":{"rendered":"https:\/\/cindypotvin.com\/?p=4427"},"modified":"2022-10-20T17:11:11","modified_gmt":"2022-10-20T21:11:11","slug":"hosting-a-static-website-for-free-in-15-minutes-with-cloudflare-workers-sites","status":"publish","type":"post","link":"https:\/\/cindypotvin.com\/hosting-a-static-website-for-free-in-15-minutes-with-cloudflare-workers-sites\/","title":{"rendered":"Hosting a static website for free in 15 minutes with Cloudflare Workers Sites"},"content":{"rendered":"
I’ve had an old school PHP hosting for ages, and I’m currently moving all the sites I’m hosting there to newer and more effective technologies. <\/p>\n\n\n\n
I have a few static sites included in the mix: I’ve been writing pure HTML + CSS for so long that it’s still my favorite solution if I want to spin up a quick landing page for a project.<\/p>\n\n\n\n
The best solution for me ended up being Cloudflare’s Worker Sites. The setup is simpler than using a static page generator, and once it’s done a new version can be deployed in an instant with a single command. The server is quick, and it’s free (up to a decent bit of traffic)! <\/p>\n\n\n\n
Cloudflare also has a Pages product that takes the static result of a build from a git repository from a site built with tools such as React, but I have not tested it, and my use case is simple enough right now that it’s not worth setting up a git repo for each site.<\/p>\n\n\n\n
I decided to start the move with one of my newest project: http:\/\/manibas.com<\/a>, a site to sell my hand cranked socks. For a quick rundown of the landing page :<\/p>\n\n\n\n You’ll need the LTS version of NodeJS to install the required tool, a free Cloudflare account and a domain name to point to the site that’s already going through Cloudflare.<\/p>\n\n\n\n You also need an To deploy the site, you need to install Wrangler, the command line tool to work with Cloudflare Workers. In any folder, run After having installed Wrangler, initialize the project from the folder you want to use, which will create a There is a small bit missing, since you’ll most likely have more than just a Prerequisites<\/h2>\n\n\n\n
index.html<\/code> file ready to deploy (ideally with a few other assets like images).<\/p>\n\n\n\n
Setting up the project<\/h2>\n\n\n\n
npm install<\/code> to install the tool globally:<\/p>\n\n\n\n
npm install -g wrangler<\/code><\/pre>\n\n\n\n
package.json<\/code> and the required boilerplate:<\/p>\n\n\n\n
npx wrangler init -y<\/code><\/pre>\n\n\n\n
index.html<\/code> file and will need to route to other static assets such as images, fonts or an external CSS file. Install the package that handles routing to static assets inside Cloudflare Workers:<\/p>\n\n\n\n
npm install --save-dev @cloudflare\/kv-asset-handler<\/code><\/pre>\n\n\n\n