2
2
3
3
Use this worker to password-protect whole websites or some areas/specific pages.
4
4
5
- E .g. limit access to a staging version of a static website you're building.
5
+ _ E .g. limit access to a staging version of a website you're building._
6
6
7
7
## Demo
8
8
@@ -15,6 +15,78 @@ User name: `demouser`
15
15
16
16
Password: ` demopassword `
17
17
18
+ ## How to use
19
+
20
+ Requirements:
21
+
22
+ - your website's DNS is managed by Cloudflare
23
+ - corresponding DNS record is proxied (orange cloud)
24
+
25
+ In order to protect your website with this worker you will
26
+ need to deploy worker code and configure route mapping.
27
+ There are multiple ways you can deploy workers, here are couple options for your
28
+ consideration.
29
+
30
+ ### Option #1 . Deploy manually via CF dashboard
31
+
32
+ If you care about _ Infrastructure as Code_ , skip to Option #2 .
33
+
34
+ Create a worker.
35
+
36
+ - Go to Cloudflare Dashboard / Account Home / ` Workers `
37
+ - ` Create a Worker `
38
+ - Paste the code
39
+ - ` Save and Deploy `
40
+
41
+ Configure route mapping.
42
+
43
+ - Go to Account Home / Domain / ` Workers `
44
+ - ` Add route `
45
+ - Provide route, e.g. example.com/protected/\*
46
+ - Select worker
47
+ - ` Save `
48
+
49
+ You're set! If you open ` example.com/protected/anything ` now it will prompt you
50
+ to enter password.
51
+
52
+ ### Option #2 . Deploy with Wrangler
53
+
54
+ Wrangler is a tool built by Cloudflare to develop, test and deploy workers code.
55
+ For more thorough overview, check
56
+ [ documentation] ( https://developers.cloudflare.com/workers/quickstart ) .
57
+
58
+ First you need to collect some information from your CF account.
59
+
60
+ - Account ID.
61
+ - Account Home / Domain / ` Overview ` tab / ` API ` section / ` Account ID `
62
+ - Zone ID.
63
+ - Account Home / Domain / ` Overview ` tab / ` API ` section / ` Zone ID `
64
+ - API token.
65
+ - Account Home / Domain / ` Overview ` tab / ` API ` section / ` Get API Token `
66
+ - ` Create Token `
67
+ - ` Start with Template `
68
+ - Select the ` Edit Cloudflare Workers ` template
69
+ - ` Continue to Summary `
70
+ - ` Create Token `
71
+
72
+ Install Wrangler. ` npm install -g @cloudflare/wrangler `
73
+
74
+ Create Wrangler config. ` wrangler init --type javascript `
75
+
76
+ Update Wrangler config. Example:
77
+
78
+ ```
79
+ name = "cf-worker-basic-http-auth"
80
+ type = "javascript"
81
+ account_id = "<YOUR ACCOUNT ID>"
82
+ zone_id = "<YOUR ZONE ID>"
83
+ route = "example.com/protected/*"
84
+ ```
85
+
86
+ Configure API token. ` wrangler config `
87
+
88
+ Deploy worker. ` wrangler publish `
89
+
18
90
## Contributing
19
91
20
92
see [ CONTRIBUTING.md] ( CONTRIBUTING.md )
0 commit comments