From 7e31acd0a76412b03fc51ba3447a0bd506cb0d74 Mon Sep 17 00:00:00 2001 From: Callum Macdonald Date: Sat, 23 Nov 2024 20:05:23 +0000 Subject: [PATCH] Take AMQP_URL as an env var. --- nr-server/mod.ts | 6 +++++- nr-server/src/consume.ts | 15 +++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/nr-server/mod.ts b/nr-server/mod.ts index fa69fc0..8c3b8a4 100644 --- a/nr-server/mod.ts +++ b/nr-server/mod.ts @@ -32,6 +32,10 @@ await new cliffy.Command() "SUBSCRIBE=", "Subscribe to relays to fetch events instead of using AMQP." ) + .env( + "AMQP_URL=", + "The URL to connect to AMQP, like amqp://insecure:insecure@localhost:5672" + ) .action((options) => { const { isDev } = options; const privateKey = getOrCreatePrivateKey(options.privateKeyNsec); @@ -42,7 +46,7 @@ await new cliffy.Command() if (options.subscribe) { subscribeAndRepost(privateKey, isDev, maxAgeMinutes); } else { - consume(privateKey, isDev); + consume(privateKey, isDev, options.amqpUrl); } }) .parse(Deno.args); diff --git a/nr-server/src/consume.ts b/nr-server/src/consume.ts index 4e0bcdc..8d1ba06 100644 --- a/nr-server/src/consume.ts +++ b/nr-server/src/consume.ts @@ -6,13 +6,20 @@ import { processEventFactoryFactory } from "./validation/repost.ts"; const exchangeName = "nostrEvents"; const queueName = "repost"; -export async function consume(privateKey: Uint8Array, isDev: true | undefined) { +export async function consume( + privateKey: Uint8Array, + isDev: true | undefined, + amqpUrl?: string +) { const relayPool = await getRelayPool(isDev); const processEventFactory = processEventFactoryFactory(relayPool, privateKey); - const connection = await amqp.connect( - "amqp://insecure:insecure@localhost:5672" - ); + const amqpUrlActual = + typeof amqpUrl === "string" && amqpUrl.length > 0 + ? amqpUrl + : "amqp://insecure:insecure@localhost:5672"; + + const connection = await amqp.connect(amqpUrlActual); const channel = await connection.openChannel(); await channel.declareExchange({ exchange: exchangeName,