mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-05 15:00:30 +03:00
Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
3d885ec262
commit
a83aecaa69
13 changed files with 850 additions and 708 deletions
|
|
@ -2,15 +2,18 @@ import initMatrix from '../client/initMatrix';
|
|||
|
||||
const WELL_KNOWN_URI = '/.well-known/matrix/client';
|
||||
|
||||
async function getBaseUrl(homeserver) {
|
||||
const serverDiscoveryUrl = `https://${homeserver}${WELL_KNOWN_URI}`;
|
||||
async function getBaseUrl(servername) {
|
||||
let protocol = 'https://';
|
||||
if (servername.match(/^https?:\/\//) !== null) protocol = '';
|
||||
const serverDiscoveryUrl = `${protocol}${servername}${WELL_KNOWN_URI}`;
|
||||
try {
|
||||
const result = await fetch(serverDiscoveryUrl, { method: 'GET' });
|
||||
const data = await result.json();
|
||||
const result = await (await fetch(serverDiscoveryUrl, { method: 'GET' })).json();
|
||||
|
||||
return data?.['m.homeserver']?.base_url;
|
||||
const baseUrl = result?.['m.homeserver']?.base_url;
|
||||
if (baseUrl === undefined) throw new Error();
|
||||
return baseUrl;
|
||||
} catch (e) {
|
||||
throw new Error('Homeserver not found');
|
||||
throw new Error(`${protocol}${servername}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue