/rsslay

A Nostr relay that creates profiles from RSS or Atom feeds and emits items as Nostr events

Primary LanguageGoThe UnlicenseUnlicense

rsslay

Fly Deploy CI Dive Check Publish Docker image Docker Hub

Go Report Card Go Reference

Relay that creates virtual nostr profiles for each RSS feed submitted

Working relay: wss://rsslay.nostr.moe. Frontend available in rsslay.nostr.moe.

  • A Nostr relay implementation based on relayer by fiatjaf.
  • Doesn't accept any events, only emits them.
  • Does so by manually reading and parsing RSS feeds.

Deploy on Railway

Screenshot of main page

API

rsslay exposes an API to work with it programmatically, so you can automate feed creation and retrieval. The following operations are available:

Get/Create a feed

  • Path: /api/feed
  • Method: GET or POST
  • Query params (mandatory): url
  • Example: GET https://rsslay.nostr.moe/api/feed?url=https://www.engadget.com/rss.xml
  • Result: application/json
  • Example result:
    {
      "PubKey": "1e630062dd55226058224a0a1e9b54e09ac121ed13dd5070758816a9c561aeab",
      "NPubKey": "npub1re3sqcka253xqkpzfg9pax65uzdvzg0dz0w4qur43qt2n3tp464sswsn92",
      "Url": "https://www.engadget.com/rss.xml",
      "Error": false,
      "ErrorMessage": "", 
      "ErrorCode": 0
    }

Example with cURL:

curl --location --request GET \ 
'https://rsslay.nostr.moe/api/feed?url=https://nitter.moomoo.me/suhail/rss'

Running the relay from the source

  1. Clone this repository (or fork it).

  2. Set the SECRET environment variable (a random string to be used to generate virtual private keys).

  3. Set the following flags (may differ per environment):

    export CGO_ENABLED=1
    export GOARCH=amd64
    export GOOS=linux
  4. Proceed to build the binary with the following command:

    go build -ldflags="-s -w -linkmode external -extldflags '-static'" -o ./rsslay
  5. Run the relay!

    ./rsslay

Note: it will create a local database file to store the currently known RSS feed URLs.

Environment variables used

  • SECRET: mandatory, a random string to be used to generate virtual private keys.
  • DB_DIR: path with filename where the database should be created, defaults to .\db\rsslay.sqlite.
  • DEFAULT_PROFILE_PICTURE_URL: default profile picture URL for feeds that don't have an image.
  • REPLAY_TO_RELAYS: set to true if you want to send the fetched events to other relays defined in RELAYS_TO_PUBLISH_TO (default is false)
  • RELAYS_TO_PUBLISH_TO: string with relays separated by , to re-publish events to in format wss://[URL],wss://[URL2] where URL and URL2 are URLs of valid relays (default is empty)
  • DEFAULT_WAIT_TIME_BETWEEN_BATCHES: default time to wait between sending batches of requests to other relays in milliseconds (default 60000, 60 seconds)
  • DEFAULT_WAIT_TIME_FOR_RELAY_RESPONSE: default time to wait for relay response for possible auth event in milliseconds (default is 3000, 3 seconds).
  • MAX_EVENTS_TO_REPLAY: maximum number of events to send to a relay in RELAYS_TO_PUBLISH_TO in a batch
  • ENABLE_AUTO_NIP05_REGISTRATION: enables NIP-05 automatic registration for all feed profiles in the format [URL]@[MAIN_DOMAIN_NAME] where URL is the main URL for the feed and MAIN_DOMAIN_NAME the below environment variable (default false)
  • MAIN_DOMAIN_NAME: main domain name where this relay will be available (only for NIP-05 purposes if enabled with ENABLE_AUTO_NIP05_REGISTRATION)
  • OWNER_PUBLIC_KEY: public key to show at the /.well-known/nostr.json endpoint by default mapped as the domain owner (_@[MAIN_DOMAIN_NAME] where MAIN_DOMAIN_NAME is the environment variable)
  • MAX_SUBROUTINES: maximum number to maintain in order to replay events to other relays (to prevent crash, default 20)

Running with Docker

The Docker image for this project is published in GitHub Packages and Docker Hub, so you can directly pull the image from that feeds.

Nevertheless, you can always use the git repository and its source code to build and run it by yourself.

From the published releases

  1. Pull the image from GitHub or Docker Hub (both are the same):
    # From GitHub (you can change the tag to a specific version)
    docker pull ghcr.io/piraces/rsslay:latest
    # From DockerHub (you can change the tag to a specific version)
    docker pull piraces/rsslay:latest
  2. Copy the .env.sample file to .env and replace the variable values as needed.
  3. Run the final image!
    # This will run in "detached" mode exposing the port 8080, change the port as needed
    # In case you downloaded the image from DockerHub
    docker run -d --env-file .env -p 8080:8080 --name rsslay piraces/rsslay:latest
    # If you downloaded the image from GitHub
    docker run -d --env-file .env -p 8080:8080 --name rsslay ghcr.io/piraces/rsslay:latest
  4. Now you can access the instance in localhost:8080 (or other port you choose).

Directly from the repository

Note: you can skip step 2 and 3 from below and directly go and run:

docker build github.com/piraces/rsslay -t rsslay
  1. Make sure you have already installed Docker.
  2. Clone this repository (or fork it).
  3. Perform a docker build:
    docker build . -t rsslay
  4. Copy the .env.sample file to .env and replace the variable values as needed.
  5. Run the final image!
    # This will run in "detached" mode exposing the port 8080, change the port as needed
    docker run -d --env-file .env -p 8080:8080 --name rsslay rsslay
  6. Now you can access the instance in localhost:8080 (or other port you choose).

Deploying easily with litefs to fly.io

I'm currently deploying an instance of rsslay into fly.io, so I made it simple to everyone to deploy to there.

The requisites are the following:

  • An account in fly.io.
  • An app instance previously created.
  • A volume to handle the database files between deployments, restarts and others.
  • (Optional) a custom domain of our own that we can set a CNAME record to and avoid using the default domain.

Setting up the app

  1. Download the flyctl CLI.
  2. Login into your account with flyctl auth login.
  3. Modify the file fly.toml replacing the property app with your app name.
  4. Create a new volume for your app with flyctl volumes create rsslay_data (the name rsslay_data can be changed).
  5. Modify the file fly.toml and set the section [mounts] accordingly (the source property with the volume name and keep destination as it is due to LiteFS usage).
  6. Create a secret with flyctl secrets set SECRET=YOUR_LONG_STRING_HERE, in order to establish the SECRET environment variable to create private keys with.
  7. Proceed with the automatic deployment with flyctl launch
  8. Optional: set up a CNAME record and set a certificate for the app.
  9. Optional: set up a workflow in GitHub to automatically deploy your app like in this repo.

You are done! And you can scale your app simply following this steps!

Contributing

Feel free to open an issue, provide feedback in discussions, or fork the repo and open a PR with your contribution!

All kinds of contributions are welcome!

Contact

You can reach me on nostr npub1ftpy6thgy2354xypal6jd0m37wtsgsvcxljvzje5vskc9cg3a5usexrrtq

Also on the bird site, and Mastodon.

License

Unlicense.