add a way to set user agent

Signed-off-by: Yonle <yonle@lecturify.net>
This commit is contained in:
Yonle 2025-01-06 22:27:40 +07:00
parent d3c73eb05a
commit 499e765a28
3 changed files with 4 additions and 4 deletions

View File

@ -33,7 +33,7 @@ if (!config.relays?.length) (async () => {
console.log("Load balancer mode. Fetching relays list from", config.loadbalancer[0].replace(/^ws/, "http")); console.log("Load balancer mode. Fetching relays list from", config.loadbalancer[0].replace(/^ws/, "http"));
const request = await undici.request(config.loadbalancer[0].replace(/^ws/, "http"), { const request = await undici.request(config.loadbalancer[0].replace(/^ws/, "http"), {
headers: { headers: {
"User-Agent": `Bostr ${version}; The nostr relay bouncer; https://codeberg.org/Yonle/bostr; ${config.server_meta.canonical_url || "No canonical bouncer URL specified"}; Contact: ${config.server_meta.contact}` "User-Agent": config.user_agent
} }
}); });

View File

@ -1,6 +1,6 @@
{ {
"name": "bostr", "name": "bostr",
"version": "3.0.10", "version": "3.1.0",
"description": "Nostr relay bouncer", "description": "Nostr relay bouncer",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@ -7,7 +7,7 @@ const WebSocket = require("ws");
const { validateEvent, nip19, matchFilters, mergeFilters, getFilterLimit } = require("nostr-tools"); const { validateEvent, nip19, matchFilters, mergeFilters, getFilterLimit } = require("nostr-tools");
const nip42 = require("./nip42.js"); const nip42 = require("./nip42.js");
let { relays, log_about_relays, server_meta, private_keys, reconnect_time, wait_eose, pause_on_limit, max_eose_score, upstream_ratelimit_expiration, max_client_subs, idle_sessions, cache_relays, loadbalancer, max_known_events } = require(process.env.BOSTR_CONFIG_PATH || "./config"); let { relays, log_about_relays, server_meta, private_keys, reconnect_time, wait_eose, pause_on_limit, max_eose_score, upstream_ratelimit_expiration, max_client_subs, idle_sessions, cache_relays, loadbalancer, max_known_events, user_agent } = require(process.env.BOSTR_CONFIG_PATH || "./config");
log_about_relays = process.env.LOG_ABOUT_RELAYS || log_about_relays; log_about_relays = process.env.LOG_ABOUT_RELAYS || log_about_relays;
loadbalancer = loadbalancer || []; loadbalancer = loadbalancer || [];
@ -292,7 +292,7 @@ class Session extends WebSocket {
if (!stats[addr]) stats[addr] = { raw_rx: 0, rx: 0, tx: 0, f: 0 }; if (!stats[addr]) stats[addr] = { raw_rx: 0, rx: 0, tx: 0, f: 0 };
super(addr, { super(addr, {
headers: { headers: {
"User-Agent": `Bostr ${version}; The nostr relay bouncer; https://codeberg.org/Yonle/bostr; ConnID: ${id}; ${server_meta.canonical_url || "No canonical bouncer URL specified"}; Contact: ${server_meta.contact}`, "User-Agent": user_agent,
} }
}); });