Fix #100: API endpoint enhancement

Bypassing Nginx for API call originated from Prosody (if Peertube >=5.1).
Can also fix some Docker setup, which needed to set the prosody-peertube-uri settings.
This commit is contained in:
John Livingston
2023-08-02 17:05:37 +02:00
committed by John Livingston
parent f7a32e95d4
commit 609b9e99ec
39 changed files with 648 additions and 85 deletions

View File

@ -174,10 +174,32 @@ async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<Pros
const publicServerUrl = options.peertubeHelpers.config.getWebserverUrl()
let basePeertubeUrl = settings['prosody-peertube-uri'] as string
if (basePeertubeUrl && !/^https?:\/\/[a-z0-9.-_]+(?::\d+)?$/.test(basePeertubeUrl)) {
throw new Error('Invalid prosody-peertube-uri')
if (basePeertubeUrl) {
logger.debug('basePeertubeUrl for internal API: using the settings value')
if (!/^https?:\/\/[a-z0-9.-_]+(?::\d+)?$/.test(basePeertubeUrl)) {
throw new Error('Invalid prosody-peertube-uri')
}
}
if (!basePeertubeUrl && ('getServerListeningConfig' in options.peertubeHelpers.config)) {
// Peertube >=5.1 has getServerListeningConfig to get relevant information.
const listeningConfig = options.peertubeHelpers.config.getServerListeningConfig()
if (listeningConfig?.port) {
if (!listeningConfig.hostname || listeningConfig.hostname === '::') {
logger.debug(
'basePeertubeUrl for internal API: getServerListeningConfig.hostname==="' +
(listeningConfig.hostname ?? '') +
'", fallbacking on 127.0.0.1.'
)
basePeertubeUrl = `http://127.0.0.1:${listeningConfig.port}`
} else {
logger.debug('basePeertubeUrl for internal API: using getServerListeningConfig')
basePeertubeUrl = `http://${listeningConfig.hostname}:${listeningConfig.port}`
}
}
}
if (!basePeertubeUrl) {
// In still nothing, just using the public url (it will get througt nginx, but will work)
logger.debug('basePeertubeUrl for internal API: using public Url')
basePeertubeUrl = publicServerUrl
}
const baseApiUrl = basePeertubeUrl + getBaseRouterRoute(options) + 'api/'