Fix broken API diagnostic.
* Moving http_peertubelivechat_test module in muc component, as the global config has no http_host. * Adding Host HTTP Header to API call from Peertube to Prosody
This commit is contained in:
parent
2d659b6522
commit
40ad9629fc
@ -7,6 +7,10 @@
|
||||
* Builtin Prosody: list existing rooms in the settings page
|
||||
* Builtin Prosody: new settings to enable local C2S. For example, can be used with Matterbridge (thanks https://github.com/tytan652)
|
||||
|
||||
### Fixes
|
||||
|
||||
* Fix broken API diagnostic.
|
||||
|
||||
## v3.1.0
|
||||
|
||||
### Features
|
||||
|
@ -21,12 +21,14 @@ export async function diagProsody (test: string, options: RegisterServerOptions)
|
||||
// FIXME: these tests are very similar to tests in testProsodyCorrectlyRunning. Remove from here?
|
||||
// Testing the prosody config file.
|
||||
let prosodyPort: string
|
||||
let prosodyHost: string
|
||||
try {
|
||||
const wantedConfig = await getProsodyConfig(options)
|
||||
const filePath = wantedConfig.paths.config
|
||||
|
||||
result.messages.push(`Prosody will run on port '${wantedConfig.port}'`)
|
||||
prosodyPort = wantedConfig.port
|
||||
prosodyHost = wantedConfig.host
|
||||
|
||||
result.messages.push(`Prosody will use ${wantedConfig.baseApiUrl} as base uri from api calls`)
|
||||
|
||||
@ -99,7 +101,8 @@ export async function diagProsody (test: string, options: RegisterServerOptions)
|
||||
const testResult = await got(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
authorization: 'Bearer ' + await getAPIKey(options)
|
||||
authorization: 'Bearer ' + await getAPIKey(options),
|
||||
host: prosodyHost
|
||||
},
|
||||
responseType: 'json',
|
||||
resolveBodyOnly: true
|
||||
@ -120,7 +123,8 @@ export async function diagProsody (test: string, options: RegisterServerOptions)
|
||||
const testResult = await got(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
authorization: 'Bearer ' + await getAPIKey(options)
|
||||
authorization: 'Bearer ' + await getAPIKey(options),
|
||||
host: prosodyHost
|
||||
},
|
||||
responseType: 'json',
|
||||
resolveBodyOnly: true
|
||||
|
@ -66,6 +66,7 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise<Pro
|
||||
interface ProsodyConfig {
|
||||
content: string
|
||||
paths: ProsodyFilePaths
|
||||
host: string
|
||||
port: string
|
||||
baseApiUrl: string
|
||||
}
|
||||
@ -137,7 +138,8 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise<Prosod
|
||||
content,
|
||||
paths,
|
||||
port,
|
||||
baseApiUrl
|
||||
baseApiUrl,
|
||||
host: prosodyDomain
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,9 +248,9 @@ class ProsodyConfigContent {
|
||||
}
|
||||
|
||||
useTestModule (prosodyApikey: string, apiurl: string): void {
|
||||
this.global.add('modules_enabled', 'http_peertubelivechat_test')
|
||||
this.global.set('peertubelivechat_test_apikey', prosodyApikey)
|
||||
this.global.set('peertubelivechat_test_peertube_api_url', apiurl)
|
||||
this.muc.add('modules_enabled', 'http_peertubelivechat_test')
|
||||
this.muc.set('peertubelivechat_test_apikey', prosodyApikey)
|
||||
this.muc.set('peertubelivechat_test_peertube_api_url', apiurl)
|
||||
}
|
||||
|
||||
setLog (level: ProsodyLogLevel, syslog?: ProsodyLogLevel[]): void {
|
||||
|
@ -195,7 +195,10 @@ async function ensureProsodyRunning (options: RegisterServerOptions): Promise<vo
|
||||
})
|
||||
|
||||
// Set the http-bind route.
|
||||
changeHttpBindRoute(options, config.port)
|
||||
changeHttpBindRoute(options, {
|
||||
host: config.host,
|
||||
port: config.port
|
||||
})
|
||||
|
||||
async function sleep (ms: number): Promise<any> {
|
||||
return new Promise((resolve) => {
|
||||
|
@ -13,7 +13,11 @@ const fs = require('fs').promises
|
||||
const proxy = require('express-http-proxy')
|
||||
|
||||
let httpBindRoute: RequestHandler
|
||||
let prosodyPort: string | undefined
|
||||
interface ProsodyHttpBindInfo {
|
||||
host: string
|
||||
port: string
|
||||
}
|
||||
let currentProsodyHttpBindInfo: ProsodyHttpBindInfo | null = null
|
||||
|
||||
async function initWebchatRouter (options: RegisterServerOptions): Promise<Router> {
|
||||
const {
|
||||
@ -124,15 +128,16 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise<Route
|
||||
return
|
||||
}
|
||||
|
||||
if (!prosodyPort) {
|
||||
if (!currentProsodyHttpBindInfo) {
|
||||
throw new Error('It seems that prosody is not binded... Cant list rooms.')
|
||||
}
|
||||
const apiUrl = `http://localhost:${prosodyPort}/peertubelivechat_list_rooms/list-rooms`
|
||||
const apiUrl = `http://localhost:${currentProsodyHttpBindInfo.port}/peertubelivechat_list_rooms/list-rooms`
|
||||
peertubeHelpers.logger.debug('Calling list rooms API on url: ' + apiUrl)
|
||||
const rooms = await got(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
authorization: 'Bearer ' + await getAPIKey(options)
|
||||
authorization: 'Bearer ' + await getAPIKey(options),
|
||||
host: currentProsodyHttpBindInfo.host
|
||||
},
|
||||
responseType: 'json',
|
||||
resolveBodyOnly: true
|
||||
@ -150,20 +155,25 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise<Route
|
||||
return router
|
||||
}
|
||||
|
||||
function changeHttpBindRoute ({ peertubeHelpers }: RegisterServerOptions, port: string | null): void {
|
||||
function changeHttpBindRoute (
|
||||
{ peertubeHelpers }: RegisterServerOptions,
|
||||
prosodyHttpBindInfo: ProsodyHttpBindInfo | null
|
||||
): void {
|
||||
const logger = peertubeHelpers.logger
|
||||
logger.info('Changing http-bind port for ' + (port ?? 'null'))
|
||||
if (port !== null && !/^\d+$/.test(port)) {
|
||||
logger.error('Port is not valid. Replacing by null')
|
||||
port = null
|
||||
if (prosodyHttpBindInfo && !/^\d+$/.test(prosodyHttpBindInfo.port)) {
|
||||
logger.error(`Port '${prosodyHttpBindInfo.port}' is not valid. Replacing by null`)
|
||||
prosodyHttpBindInfo = null
|
||||
}
|
||||
if (port === null) {
|
||||
prosodyPort = undefined
|
||||
|
||||
if (!prosodyHttpBindInfo) {
|
||||
logger.info('Changing http-bind port for null')
|
||||
currentProsodyHttpBindInfo = null
|
||||
httpBindRoute = (_req: Request, res: Response, _next: NextFunction) => {
|
||||
res.status(404)
|
||||
res.send('Not found')
|
||||
}
|
||||
} else {
|
||||
logger.info('Changing http-bind port for ' + prosodyHttpBindInfo.port + ', on host ' + prosodyHttpBindInfo.host)
|
||||
const options: ProxyOptions = {
|
||||
https: false,
|
||||
proxyReqPathResolver: async (_req: Request): Promise<string> => {
|
||||
@ -173,8 +183,8 @@ function changeHttpBindRoute ({ peertubeHelpers }: RegisterServerOptions, port:
|
||||
parseReqBody: true // Note that setting this to false overrides reqAsBuffer and reqBodyEncoding below.
|
||||
// FIXME: should we remove cookies?
|
||||
}
|
||||
prosodyPort = port
|
||||
httpBindRoute = proxy('http://localhost:' + port, options)
|
||||
currentProsodyHttpBindInfo = prosodyHttpBindInfo
|
||||
httpBindRoute = proxy('http://localhost:' + prosodyHttpBindInfo.port, options)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user