From ad68b61ad1aa5a1ba3eff872547439f8998b3178 Mon Sep 17 00:00:00 2001 From: jjj333_p Date: Sat, 23 Mar 2024 02:47:52 -1000 Subject: [PATCH] more configurable endpoint locations --- examples/login.yaml | 10 ++++------ index.js | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/examples/login.yaml b/examples/login.yaml index a5514f3..da0b67e 100644 --- a/examples/login.yaml +++ b/examples/login.yaml @@ -4,13 +4,11 @@ # The address that the homeserver client api is reached on # The safest setting will always to be the direct domain of dendrite, for pain.agency this would be https://matrix.pain.agency (delegation) # for some reason it will bork if you try to input a localhost address. Perhaps it is attempting to make a SSL connection -homeserverUrl: 'http://matrix.' +homeserverUrl: 'https://matrix.' -# Localhost port to run endpoints on -# Dendrite endpoints must be run from localhost. -# IIRC 8008 is the default/expected configuration for dendrite to be available on localhost - -port: '8008' +# Dddress for endpoints to be ran on +# With the default/expected Dendrite config the admin endpoints will only be available from localhost +curlAddress: 'http://localhost:8008' # The login token for the bot to use # This should be an admin account as the bot will use this to run Dendrite admin endpoints from diff --git a/index.js b/index.js index f7873d6..257ee36 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,7 @@ import crypto from "node:crypto"; let loginFile = fs.readFileSync("./db/login.yaml", "utf8"); const loginParsed = yaml.load(loginFile); const homeserver = loginParsed.homeserverUrl; -const port = loginParsed.port; +const addr = loginParsed.curlAddress; const accessToken = loginParsed.loginToken; let adminRoom = loginParsed.administrationRoom; const prefix = loginParsed.prefix; @@ -171,7 +171,7 @@ Makes an internal request to the global `homeserver` address following standard async function makeAdminReq(software, reqType, command, arg1, arg2, body) { //base url guaranteed to always be there //Dendrite only accepts requests from localhost - let url = `http://localhost:${port}/${software}/admin/${command}`; + let url = `${addr}/${software}/admin/${command}`; //if there is a first argument add it if (arg1) url += `/${arg1}`; @@ -216,7 +216,7 @@ async function makeAdminReq(software, reqType, command, arg1, arg2, body) { async function makeUserReq(reqType, command, arg1, arg2, userToken, body) { //base url guaranteed to always be there //Dendrite only accepts requests from localhost - let url = `http://localhost:${port}/_matrix/client/v3/${command}`; + let url = `${addr}/_matrix/client/v3/${command}`; //if there is a first argument add it if (arg1) url += `/${arg1}`; @@ -326,7 +326,7 @@ async function createAccount(username, suppliedPwd) { //get nonce const nonce = ( await ( - await fetch(`http://localhost:${port}/_synapse/admin/v1/register`, { + await fetch(`${addr}/_synapse/admin/v1/register`, { method: "GET", }) ).json()