Find matrix server with a domain name
import { matrixResolve } from 'matrix-resolve'
const baseUrl = await matrixResolve('mydomain.com')
or using Object interface:
import { MatrixResolve } from 'matrix-resolve'
const matrixResolve = new MatrixResolve({
// optional cache
cache: 'toad-cache',
cacheSize: 100,
cacheTtl: 300,
})
const baseUrl = await matrixResolve.resolve('mydomain.com')
matrix-resolve permits to find the base URL of a Matrix "server name". Following the specification it tries to resolve the url in the following order:
-
If the hostname is an IP literal, then it builds base URL using that IP address together with the given port number, or 8448 if no port is given.
-
If the hostname is not an IP literal, and the server name includes an explicit port, it builds base URL using this hostname and the given port
-
Tries a request to
https://<hostname>/.well-known/matrix/server
to get a delegated hostname (value ofm.server
field). If success:- If delegated hostname is an IP literal, it builds base URL using that IP together with the delegated port or 8448 if no port is provided
- If delegated hostname is not an IP literal and delegated port is present, it builds base URL using that name with the delegated port
- Else follow the next points but using delegated hostname instead of hostname
-
Tries to found a DNS SRV record using
_matrix-fed._tcp.<hostname>
, if succeed, it build URL using name and port given by the SRV entry. Returns an array if more than one entry is found, sorted by priority -
[Deprecated] Try to found a DNS SRV record using
_matrix._tcp.<hostname>
, if succeed, it build URL using name and port given by the SRV entry Returns an array if more than one entry is found, sorted by priority -
Verifies that hostname exists in DNS and builds URL using hostname and port 8448
You can use either the simple interface or the Object one. With the Object interface, you can add a cache (only toad-cache is supported for now).
The constructor take an optional object argument. Constructor argument keys:
- cache: cache type. For now, only toad-cache is accepted
- cacheSize: the max number of responses to store. Default: 500
- cacheTtl: the time-to-live in seconds. Default: 600
Copyright (c) 2023-present Linagora https://linagora.com
License: GNU AFFERO GENERAL PUBLIC LICENSE