Created
May 23, 2026 05:24
-
-
Save darashi/bd75be4fca18b4ed90c3685a30b247ea to your computer and use it in GitHub Desktop.
Kyomu Nostr Relay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # frozen_string_literal: true | |
| require "bundler/inline" | |
| gemfile do | |
| source "https://rubygems.org" | |
| gem "falcon", "~> 0.55.3" | |
| gem "async-websocket", "~> 0.30.0" | |
| end | |
| require "json" | |
| require "async/websocket/adapters/rack" | |
| require "falcon/rackup/handler" | |
| app = lambda do |env| | |
| Async::WebSocket::Adapters::Rack.open(env, protocols: ["ws"]) do |connection| | |
| while message = connection.read | |
| payload = JSON.parse(message) | |
| case payload[0] | |
| when "EVENT" | |
| connection.write JSON.dump(["OK", payload[1], true, ""]) | |
| when "REQ" | |
| connection.write JSON.dump(["EOSE", payload[1]]) | |
| end | |
| connection.flush | |
| end | |
| end or [200, {}, ["Please use a Nostr client to connect."]] | |
| end | |
| puts "Falcon listening on http://localhost:9292" | |
| begin | |
| Falcon::Rackup::Handler.run(app, Host: "localhost", Port: 9292) | |
| rescue Interrupt | |
| end |
Comments are disabled for this gist.