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