Implement getServerListeningConfig plugin helper

This commit is contained in:
Chocobozzz 2023-01-04 11:52:45 +01:00
parent 518c5cc62d
commit 60bab7b540
No known key found for this signature in database
GPG key ID: 583A612D890159BE
4 changed files with 25 additions and 0 deletions

View file

@ -209,6 +209,10 @@ function buildConfigHelpers () {
return WEBSERVER.URL
},
getServerListeningConfig () {
return { hostname: CONFIG.LISTEN.HOSTNAME, port: CONFIG.LISTEN.PORT }
},
getServerConfig () {
return ServerConfigManager.Instance.getServerConfig()
}

View file

@ -76,6 +76,12 @@ async function register ({
return res.json({ serverConfig })
})
router.get('/server-listening-config', async (req, res) => {
const config = await peertubeHelpers.config.getServerListeningConfig()
return res.json({ config })
})
router.get('/static-route', async (req, res) => {
const staticRoute = peertubeHelpers.plugin.getBaseStaticRoute()

View file

@ -64,6 +64,18 @@ describe('Test plugin helpers', function () {
await servers[0].servers.waitUntilLog(`server url is ${servers[0].url}`)
})
it('Should have the correct listening config', async function () {
const res = await makeGetRequest({
url: servers[0].url,
path: '/plugins/test-four/router/server-listening-config',
expectedStatus: HttpStatusCode.OK_200
})
expect(res.body.config).to.exist
expect(res.body.config.hostname).to.equal('::')
expect(res.body.config.port).to.equal(servers[0].port)
})
it('Should have the correct config', async function () {
const res = await makeGetRequest({
url: servers[0].url,

View file

@ -71,6 +71,9 @@ export type PeerTubeHelpers = {
config: {
getWebserverUrl: () => string
// PeerTube >= 5.1
getServerListeningConfig: () => { hostname: string, port: number }
getServerConfig: () => Promise<ServerConfig>
}