synapse-admin/src/index.tsx
Borislav Pantaleev 915e3564f8
Allow providing login form details via GET params (#140)
* Allow providing login form details via GET params

* add http:// to serverURL if it's only domian name

* update readme
2024-11-14 09:26:12 +02:00

50 lines
1.5 KiB
TypeScript

import React from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
import { Config, WellKnownKey, LoadConfig } from "./components/config";
import { AppContext } from "./AppContext";
import storage from "./storage";
// load config.json
let props: Config = {
restrictBaseUrl: [],
asManagedUsers: [],
supportURL: "",
menu: [],
};
try {
const resp = await fetch("config.json");
const configJSON = await resp.json();
console.log("Loaded config.json", configJSON);
props = LoadConfig(configJSON as Config);
} catch (e) {
console.error(e);
}
// if home_server is set, try to load https://home_server/.well-known/matrix/client
const homeserver = storage.getItem("home_server");
if (homeserver) {
try {
const resp = await fetch(`https://${homeserver}/.well-known/matrix/client`);
const configWK = await resp.json();
if (!configWK[WellKnownKey]) {
console.log(`Loaded https://${homeserver}.well-known/matrix/client, but it doesn't contain ${WellKnownKey} key, skipping`, configWK);
} else {
console.log(`Loaded https://${homeserver}.well-known/matrix/client`, configWK);
props = LoadConfig(configWK[WellKnownKey] as Config);
}
} catch (e) {
console.log(`https://${homeserver}/.well-known/matrix/client not found, skipping`, e);
}
}
createRoot(document.getElementById("root")).render(
<React.StrictMode>
<AppContext.Provider value={props}>
<App />
</AppContext.Provider>
</React.StrictMode>
);