Code Monkey home page Code Monkey logo

cfrelay's Introduction

cfrelay

A relay run at cloudflare.

Features

  • NIP-01 (Basic protocol flow description)
  • NIP-02 (Follow List)
  • NIP-05 (Mapping Nostr keys to DNS-based internet identifiers)
  • NIP-09 (Event Deletion)
  • NIP-11 (Relay Information Document)
  • NIP-12 (Generic Tag Queries)
  • NIP-33 (Parameterized Replaceable Events)
  • NIP-42 (Authentication of clients to relays)
  • NIP-45 (Counting results)
  • NIP-50 (Search Capability)
  • NIP-95 (Shared File)
  • NIP-96 (HTTP File Storage Integration)
  • NIP-98 (HTTP Auth)

Implement

Function Cloudflare implement
Event Store D1
File Store (NIP-95) KV
File Store (NIP-96) R2

Why do we use the KV to save the file store?

Because the R2 must bing the payment method and when it run out of the free plan limit, it would make some fee.

Deploy

1. Install NPM

2. Install wrangler

3. Init D1 database

create d1 database

wrangler d1 create relay

run init script

wrangler d1 execute relay --file=init.sql

4.Init KV

wrangler kv:namespace create relay

5.Init R2 (Optional)

If you want to use R2, you must config your payment to cloudflare. I can't ensure that it won't cost you money

After config payment, you can init the R2 bucket now. You can do it in the cloudflare website or run this script:

wrangler r2 bucket create relay

It is important that config a custom domain for your bucket. Due to this domain can user cloudflare's cache and it will save you money.

You can readmore from this Connect a bucket to a custom domain .

5.Change files

change the owners in in src/index.js, chenge the 29320975df855fe34a7b45ada2421e2c741c37c0136901fe477133a91eb18b07 to you plain owner id.

const owners = ["29320975df855fe34a7b45ada2421e2c741c37c0136901fe477133a91eb18b07"];

(Optional). change the nip05 config

// nip05user config should set like this:
const nip05User = {"nicename": "pubkey"};

(Optional). If you use R2 for NIP-96 and had config a custom domain, you should config r2CustomDomain in src/index.js.

const r2CustomDomain = 'You custom domain like: https://xxxxxx.com ';

change config file wrangler.toml set the database_id and kv_namespaces' id

[[d1_databases]]
binding = "DB"
database_name = "relay"
database_id = "Here is there d1 id"

[[kv_namespaces]]
binding = "KV"
id = "Here is there kv id"

(Optional). If you use R2 for NIP-96, you should also add this setting to wrangler.toml.

[[d1_databases]]
[[r2_buckets]]
binding = "R2"
bucket_name = "You bucket name"

6.Deploy

run this script to install project dependent

npm install

run this script to deploy

npm run deploy

cfrelay's People

Contributors

haorendashu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

itawa-panema

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.