Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/getalby/http-nostr-publisher
A Cloudflare worker to publish Nostr events to relays through a non-blocking HTTP interface
https://github.com/getalby/http-nostr-publisher
cloudflare cloudflare-workers http nostr nostr-protocol
Last synced: 20 days ago
JSON representation
A Cloudflare worker to publish Nostr events to relays through a non-blocking HTTP interface
- Host: GitHub
- URL: https://github.com/getalby/http-nostr-publisher
- Owner: getAlby
- Created: 2023-02-21T10:45:20.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-05-16T08:13:10.000Z (over 1 year ago)
- Last Synced: 2024-02-17T05:34:17.058Z (10 months ago)
- Topics: cloudflare, cloudflare-workers, http, nostr, nostr-protocol
- Language: JavaScript
- Homepage:
- Size: 60.5 KB
- Stars: 14
- Watchers: 4
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# HTTP to Nostr Cloudflare worker
This [Cloudflare worker](https://workers.cloudflare.com/) exposes a HTTP interface to publish events to specified Nostr relays.
The HTTP request is non-blocking and will immediatelly return. The events will be published asynchronously.The goal of this worker is to make it easier to integrate publishing events into any application.
Using this worker applications do not need to integrate websockets and can publish events through a non-blocking HTTP request.## API
### POST /publish
Send a JSON body with the the event and the relays that the event should be published to.
```json
{
"relays": ["relay.damus.io", "relay.snort.social"],
"event": { JSON of the EVENT }
}```
The HTTP request will immediatelly return and the the events are published asynchonously.
### POST /profile
Retrieve the profile for a pubkey.
```json
{
"relays": ["relay.damus.io", "relay.snort.social"],
"pubkey": "profile-pubkey"
}```
If a profile is already cached it will return with `HTTP status 200`.
If a profile is NOT already cached it will return with `HTTP status 202` and query the profile asynchronously.
## Configuration
#### Cloudflare KV
The profile data is cached in a [worker KV](https://developers.cloudflare.com/workers/runtime-apis/kv/) (a global, low-latency, key-value data store).
Configure the KV:
```
$ wrangler kv:namespace create PROFILES
$ wrangler kv:namespace create PROFILES --preview
```and add the `kv_namespaces` array to the wrangler.toml
#### API Token
To protect your worker you can set a `API_TOKEN` environment variable.
Clients then need to send this token in a `API-TOKEN` HTTP header.
## Deployment
Refer to the [Cloudflare docs](https://developers.cloudflare.com/workers/get-started/guide/) Learn more about Cloudflare workers and how to publish workers
```
$ wrangler publish
```## Development
```
$ wrangler dev
```