Skip to content

Commit

Permalink
more configurable endpoint locations
Browse files Browse the repository at this point in the history
  • Loading branch information
jjj333-p committed Mar 23, 2024
1 parent 70e616f commit ad68b61
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
10 changes: 4 additions & 6 deletions examples/login.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}`;
Expand Down Expand Up @@ -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}`;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ad68b61

Please sign in to comment.