Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/garrison/cloudflare-pages-shared-password
Demonstration of a static site hosted on Cloudflare Pages with HTTP basic authentication
https://github.com/garrison/cloudflare-pages-shared-password
cloudflare-pages cloudflare-pages-functions static-site
Last synced: 3 months ago
JSON representation
Demonstration of a static site hosted on Cloudflare Pages with HTTP basic authentication
- Host: GitHub
- URL: https://github.com/garrison/cloudflare-pages-shared-password
- Owner: garrison
- License: mit
- Created: 2022-05-31T23:34:56.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-06-01T22:53:41.000Z (over 2 years ago)
- Last Synced: 2024-10-12T15:21:31.042Z (3 months ago)
- Topics: cloudflare-pages, cloudflare-pages-functions, static-site
- Language: TypeScript
- Homepage: https://cloudflare-pages-shared-password.pages.dev/
- Size: 11.7 KB
- Stars: 17
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cloudflare-pages-shared-password
This repository demonstrates a static site which is hosted on Cloudflare Pages and whose content is "protected" by a shared username/password with [HTTP basic access authentication](https://en.wikipedia.org/wiki/Basic_access_authentication). The real magic is in [`functions/_middleware.ts`](https://github.com/garrison/cloudflare-pages-shared-password/blob/main/functions/_middleware.ts), which is based on the [Cloudflare Workers example for HTTP basic authentication](https://developers.cloudflare.com/workers/examples/basic-auth/), repurposed as a [middleware](https://developers.cloudflare.com/pages/platform/functions#exporting-middleware) to be used with the [Functions](https://developers.cloudflare.com/pages/platform/functions) feature of Cloudflare Pages.
This demonstration site is hosted at https://cloudflare-pages-shared-password.pages.dev/, with `admin` as both the username and password.
The static site in this repository is built using [Hugo](https://developers.cloudflare.com/pages/framework-guides/deploy-a-hugo-site/), but the middleware can be used with any static site hosted on Cloudflare Pages.
## [Non]-Security
I make no guarantees about the security of this code. In particular, a shared password, stored in a repository, should not be expected to provide a meaningful degree of security.
## Acknowledgments
Special thanks to [CherryJimbo](https://jross.me/) and [Isaac McFadyen](https://imcf.me/) for responding to my questions on the Cloudflare Discord instance. Their suggestions were essential in getting the first version of this code to work.