mirror of
https://github.com/Yonle/bostr.git
synced 2025-03-18 05:42:03 +01: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:
parent
b420125e63
commit
649c425e42
13
http.js
13
http.js
@ -8,6 +8,7 @@ const http = require("http");
|
||||
const http2 = require("http2");
|
||||
const fs = require("fs");
|
||||
const bouncer = require(`./bouncer.js`);
|
||||
const undici = require("undici");
|
||||
|
||||
// For log
|
||||
const curD = _ => (new Date()).toLocaleString("ia");
|
||||
@ -19,6 +20,18 @@ let config = require(process.env.BOSTR_CONFIG_PATH || "./config");
|
||||
|
||||
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 (
|
||||
fs.existsSync(config.https?.privKey) &&
|
||||
fs.existsSync(config.https?.certificate)
|
||||
|
Loading…
x
Reference in New Issue
Block a user