From 4cc43506ab3aefeef1e49fc86436915d98fff290 Mon Sep 17 00:00:00 2001 From: Benjamin Howe Date: Tue, 2 Jul 2024 19:39:30 +0100 Subject: [PATCH] Updated README with `wrangler` commands --- .gitignore | 1 + README.md | 20 ++++++++++++++++---- wrangler.toml | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 270bd17..84c3d59 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ _site .jekyll-metadata vendor node_modules +.wrangler diff --git a/README.md b/README.md index 48571aa..96e2dbb 100644 --- a/README.md +++ b/README.md @@ -6,17 +6,29 @@ Benjamin Howe's personal website, deployed to Cloudflare Pages. Originally gener Clone this repository in a convenient location. -To run locally without Docker [install Ruby and Jekyll](https://jekyllrb.com/docs/step-by-step/01-setup/). +To run Jekyll locally without Docker [install Ruby and Jekyll](https://jekyllrb.com/docs/step-by-step/01-setup/). Wrangler requires [Node.js](https://nodejs.org/) as unfortunately [the maintainers of Wrangler have decided against having an official container image for Wrangler](https://github.com/cloudflare/workers-sdk/issues/1316#issuecomment-1658608450). ## Usage -Install gems using `bundle install` and then run `bundle exec jekyll serve` and navigate to http://127.0.0.1:4000. - -### Using Docker +The easiest way to run Jekyll is using Docker: - Windows (cmd): `docker run -it --rm -v %cd%:/app -w /app -p 127.0.0.1:4000:4000 ruby:3.3.1 sh -c "bundle install && bundle exec jekyll serve --force_polling -H 0.0.0.0"` - macOS & Linux (bash): `docker run -it --rm -v "$PWD":/app -w /app -p 127.0.0.1:4000:4000 ruby:3.3.1 sh -c "bundle install && bundle exec jekyll serve -H 0.0.0.0"` +### Using Wrangler + +To test some of the dynamic aspects of the website (e.g. [Cloudflare Pages Functions](https://developers.cloudflare.com/pages/functions/)), it is necessary to use [Wrangler](https://developers.cloudflare.com/workers/wrangler/). + +To set up a local database: + +`npx wrangler@latest d1 execute beh-uk-forms --local --file=./sql/beh-uk-forms-schema.sql` + +(note that Windows users will need to convert the line endings in the SQL file to `LF` to work around [a bug in `workerd`](https://github.com/cloudflare/workerd/issues/1300)) + +Run the appropriate commend for Jekyll (see above) _without_ the port forward and listen hostname, then also run: + +`npx wrangler@latest pages dev --port 4000 _site` + ## Tests Sadly there aren't any, yet, at least. I plan to fix this! diff --git a/wrangler.toml b/wrangler.toml index 0c415c4..6b4961d 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -2,5 +2,6 @@ name = "beh-uk" [[d1_databases]] binding = "DB_FORMS" +preview_database_id = "DB_FORMS" database_name = "beh-uk-forms" database_id = "acb261ce-be3c-46d4-a89b-a6587eca3440"