From: Ardis Lu Date: Fri, 25 Mar 2022 07:13:08 +0000 (-0700) Subject: Update README to use wrangler for development X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=724e9c58339820a61d567b68810497c4835d5a62;p=ardislu.dev Update README to use wrangler for development --- diff --git a/README.md b/README.md index fe3257f..1dab0fb 100644 --- a/README.md +++ b/README.md @@ -12,16 +12,12 @@ I'm using Google Sheets and Google Docs as the CMS for this website. A Google Sh Once I fetch an article from the Google Docs API, the article is converted into markdown then converted into HTML using [marked](https://marked.js.org). -## Serving actual 404 errors for invalid routes while still being a SPA +## Local development -Cloudflare Pages automatically redirects any invalid routes in a directory to `404.html` if there is a `404.html` that exists in that directory. Since there's no `404.html` in the root, Cloudflare Pages will redirect all routes to `index.html`. +Use the `wrangler` CLI to serve the static frontend and API at the same time. Provide credentials for a service account with access to the Google Docs as environment variables. -I do a client-side redirect to `/errors/NotFound` for any routes that should have actually been a `404`, which Cloudflare Pages then serves a `404` with `/errors/404.html`. +From the [Cloudflare Pages documentation](https://developers.cloudflare.com/pages/platform/functions/#develop-and-preview-locally): -Here's how to replicate this behavior locally: +1. `npm i wrangler@beta` -1. Install Node.js (this is ONLY used for the web server; the website itself does not use Node.js) - -2. `npm i -g local-web-server` - -3. `ws --spa index.html --rewrite '/errors/(.*) -> /errors/404.html'` +2. `npx wrangler pages dev . --binding EMAIL=\"example@example.com" PRIVATE_KEY=\"-----BEGIN PRIVATE KEY-----\n...EXAMPLE...\n-----END PRIVATE KEY-----\n" SCOPES=\"https://example.com/auth/scope1 https://example.com/auth/scope2"`