Skip to content

Commit e7c9d9c

Browse files
committed
Move to R2 bucket
1 parent 1d2d526 commit e7c9d9c

9 files changed

+587
-338
lines changed

README.md

+41-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Nosflare
22

3-
Nosflare is a serverless [Nostr](https://github.com/fiatjaf/nostr) relay purpose-built for [Cloudflare Workers](https://workers.cloudflare.com/) and the [Cloudflare KV](https://www.cloudflare.com/products/workers-kv/) store.
3+
Nosflare is a serverless [Nostr](https://github.com/fiatjaf/nostr) relay purpose-built for [Cloudflare Workers](https://workers.cloudflare.com/) and a [Cloudflare R2](https://www.cloudflare.com/developer-platform/r2/) bucket.
44

55
This relay is designed to be easy to deploy, scalable, and cost-effective, leveraging Cloudflare's edge computing infrastructure to provide a resilient relay for the Nostr decentralized social protocol.
66

@@ -20,7 +20,7 @@ Most applicable NIPs are supported along with support for allowlisting or blockl
2020

2121
### Dependencies
2222

23-
This project requires the [@noble/curves](https://github.com/paulmillr/noble-curves) package for cryptographic operations and esbuild:
23+
This project requires the [@noble/curves](https://github.com/paulmillr/noble-curves) package for cryptographic operations and the [@evanw/esbuild](https://github.com/evanw/esbuild) bundler:
2424

2525
```
2626
npm install @noble/curves
@@ -29,7 +29,7 @@ npm install -g esbuild
2929

3030
### Building
3131

32-
Clone the `worker.js` file to your machine. Edit the contents of `relayInfo` and `relayIcon` as desired to customize the relay name, icon, etc.
32+
Clone the repo to your machine and open `worker.js` in a file editor. Edit the contents of `relayInfo` and `relayIcon` as desired to customize the relay name, icon, etc.
3333

3434
*Optional:*
3535
- Edit the `nip05Users` section to add usernames and their hex pubkey for NIP-05 verified Nostr address.
@@ -52,29 +52,41 @@ The command assumes you're in the same directory as the `worker.js` file.
5252

5353
You can deploy Nosflare using either the Wrangler CLI, directly through the Cloudflare dashboard, or with the third-party deployment script:
5454

55-
#### Using Wrangler CLI
55+
#### Cloudflare Dashboard
56+
57+
1. Log in to your Cloudflare dashboard.
58+
2. Go to the Workers section and create a new worker. You can call it whatever you'd like.
59+
3. Copy the contents of `dist/worker.js` and paste into the online editor. See the `example.js` file in this repo for what a successfully bundled file should look like.
60+
4. Save and deploy the worker.
61+
5. Add a custom domain in Worker's settings (this will be the desired relay URL).
62+
6. Create a R2 bucket to store events. You can call it whatever you want.
63+
7. In R2 bucket settings, add a custom subdomain (ex: nostr-events.site.com).
64+
8. In the Worker's variables settings add the following environment variables: `customDomain` that will be the subdomain URL you set in bucket, `apiToken` this will be your cloudflare API token (recommended to set a custom API token that only has cache purge privileges), `zoneId` which is for the domain you're using for the R2 bucket (this ID can be found in the right sidebar of the overview page for the domain).
65+
9. In a different section on the Settings > Variables page, bind the `relayDb` variable to the R2 bucket you created in the R2 Bucket Bindings section.
66+
67+
Examples:
68+
69+
![R2 Bucket Subdomain](images/custom-domain.jpeg)
70+
71+
![Environment Variables](images/env-vars.jpeg)
72+
73+
![R2 Bucket Binding](images/r2-binding.jpeg)
74+
75+
#### Wrangler CLI
5676

5777
1. Configure your `wrangler.toml` with your Cloudflare account details.
5878
2. Publish the worker:
5979

6080
```
6181
wrangler publish
6282
```
63-
3. Add a custom domain (this will be the desired relay URL).
64-
4. Create a KV namespace to store events. You can call it whatever you want.
65-
5. Bind the `relayDb` variable to the KV namespace for the Worker in the Settings > Variables tab under the "KV Namespace Bindings" section.
83+
3. Add a custom domain in Worker's settings (this will be the desired relay URL).
84+
4. Create a R2 bucket to store events. You can call it whatever you want.
85+
5. In R2 bucket settings, add a custom subdomain (ex: nostr-events.site.com).
86+
6. In the Worker's variables settings add the following environment variables: `customDomain` that will be the subdomain URL you set in bucket, `apiToken` this will be your cloudflare API token (recommended to set a custom API token that only has cache purge privileges), `zoneId` which is for the domain you're using for the R2 bucket (this ID can be found in the right sidebar of the overview page for the domain).
87+
7. In a different section on the Settings > Variables page, bind the `relayDb` variable to the R2 bucket you created in the R2 Bucket Bindings section.
6688

67-
#### Using Cloudflare Dashboard
68-
69-
1. Log in to your Cloudflare dashboard.
70-
2. Go to the Workers section and create a new worker. You can call it whatever you'd like.
71-
3. Copy the contents of `dist/worker.js` and paste into the online editor. See the `example.js` file in this repo for what a successfully bundled file should look like.
72-
4. Save and deploy the worker.
73-
5. Add a custom domain (this will be the desired relay URL).
74-
6. Create a KV namespace to store events. You can call it whatever you want.
75-
7. Bind the `relayDb` variable to the KV namespace for the Worker in the Settings > Variables tab under the "KV Namespace Bindings" section.
76-
77-
#### Using NosflareDeploy script
89+
#### NosflareDeploy Script
7890

7991
A third-party script to easily deploy Nosflare. Read more [here](https://github.com/PastaGringo/NosflareDeploy).
8092

@@ -92,11 +104,22 @@ Example:
92104

93105
The current release of Nosflare is primarily focused on [basic protocol flow](https://github.com/nostr-protocol/nips/blob/master/01.md) usage. This ensures events are stored and retrieved very quickly. However, the following is a non-exhaustive list of planned features:
94106

107+
- Event streaming
95108
- "Pay-to-relay" (charging sats for access)
96109
- Client authorization (NIP-42)
97110
- File storage through Cloudflare R2 bucket (NIP-96)
98111
- Encrypted DMs (NIP-44)
99112

113+
## Recommended Cloudflare Settings
114+
115+
Ensure optimal performance of the relay by enforcing a high cache rate and lengthy Cloudflare edge TTL as well as enabling rate limiting in order to protect the relay from abuse.
116+
117+
Examples:
118+
119+
![Cache Rule](images/cache-setting.jpeg)
120+
121+
![Rate Limiting](images/rate-limit.jpeg)
122+
100123
## Contributing
101124

102125
Contributions to Nosflare are welcome! Please submit issues, feature requests, or pull requests through the project's [GitHub repository](https://github.com/Spl0itable/nosflare).

changelog.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v3.17.13 - 2024-05-08
2+
3+
- New: integration with R2 bucket
4+
- Deprecated: use of KV store
5+
16
## v2.17.13 - 2024-04-27
27

38
- Hotfix: corrected deletion (kind 5) logic for indexation

0 commit comments

Comments
 (0)