mirror of
https://github.com/Yonle/bostr.git
synced 2025-08-04 16:32:10 +02:00
http.js: try fetch loadbalancers relay list
Ref: https://github.com/Yonle/bostr/issues/19 Signed-off-by: Yonle <yonle@lecturify.net>
This commit is contained in:
13
http.js
13
http.js
@@ -8,6 +8,7 @@ const http = require("http");
|
|||||||
const http2 = require("http2");
|
const http2 = require("http2");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const bouncer = require(`./bouncer.js`);
|
const bouncer = require(`./bouncer.js`);
|
||||||
|
const undici = require("undici");
|
||||||
|
|
||||||
// For log
|
// For log
|
||||||
const curD = _ => (new Date()).toLocaleString("ia");
|
const curD = _ => (new Date()).toLocaleString("ia");
|
||||||
@@ -19,6 +20,18 @@ let config = require(process.env.BOSTR_CONFIG_PATH || "./config");
|
|||||||
|
|
||||||
config.server_meta.version = version;
|
config.server_meta.version = version;
|
||||||
|
|
||||||
|
if (!config.relays?.length) (async () => {
|
||||||
|
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"), {
|
||||||
|
headers: {
|
||||||
|
"User-Agent": `Bostr ${version}; The nostr relay bouncer; https://github.com/Yonle/bostr`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const text = await request.text();
|
||||||
|
relays = text.match(/(w{1,2}s)s?:\/\/.+/g);
|
||||||
|
})();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
fs.existsSync(config.https?.privKey) &&
|
fs.existsSync(config.https?.privKey) &&
|
||||||
fs.existsSync(config.https?.certificate)
|
fs.existsSync(config.https?.certificate)
|
||||||
|
Reference in New Issue
Block a user