diff options
author | Chocobozzz <me@florianbigard.com> | 2023-01-04 11:52:45 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-01-04 11:52:54 +0100 |
commit | 60bab7b540de3709f3392a0ea964524c13c7e404 (patch) | |
tree | 9a3966982af2cf8c1966a2e83db0a3da4a66f1f7 | |
parent | 518c5cc62d922ddedc16f5a1e2c3e7035f342115 (diff) | |
download | PeerTube-60bab7b540de3709f3392a0ea964524c13c7e404.tar.gz PeerTube-60bab7b540de3709f3392a0ea964524c13c7e404.tar.zst PeerTube-60bab7b540de3709f3392a0ea964524c13c7e404.zip |
Implement getServerListeningConfig plugin helper
-rw-r--r-- | server/lib/plugins/plugin-helpers-builder.ts | 4 | ||||
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test-four/main.js | 6 | ||||
-rw-r--r-- | server/tests/plugins/plugin-helpers.ts | 12 | ||||
-rw-r--r-- | server/types/plugins/register-server-option.model.ts | 3 |
4 files changed, 25 insertions, 0 deletions
diff --git a/server/lib/plugins/plugin-helpers-builder.ts b/server/lib/plugins/plugin-helpers-builder.ts index e75c0b994..66383af46 100644 --- a/server/lib/plugins/plugin-helpers-builder.ts +++ b/server/lib/plugins/plugin-helpers-builder.ts | |||
@@ -209,6 +209,10 @@ function buildConfigHelpers () { | |||
209 | return WEBSERVER.URL | 209 | return WEBSERVER.URL |
210 | }, | 210 | }, |
211 | 211 | ||
212 | getServerListeningConfig () { | ||
213 | return { hostname: CONFIG.LISTEN.HOSTNAME, port: CONFIG.LISTEN.PORT } | ||
214 | }, | ||
215 | |||
212 | getServerConfig () { | 216 | getServerConfig () { |
213 | return ServerConfigManager.Instance.getServerConfig() | 217 | return ServerConfigManager.Instance.getServerConfig() |
214 | } | 218 | } |
diff --git a/server/tests/fixtures/peertube-plugin-test-four/main.js b/server/tests/fixtures/peertube-plugin-test-four/main.js index 3e848c49e..b10177b45 100644 --- a/server/tests/fixtures/peertube-plugin-test-four/main.js +++ b/server/tests/fixtures/peertube-plugin-test-four/main.js | |||
@@ -76,6 +76,12 @@ async function register ({ | |||
76 | return res.json({ serverConfig }) | 76 | return res.json({ serverConfig }) |
77 | }) | 77 | }) |
78 | 78 | ||
79 | router.get('/server-listening-config', async (req, res) => { | ||
80 | const config = await peertubeHelpers.config.getServerListeningConfig() | ||
81 | |||
82 | return res.json({ config }) | ||
83 | }) | ||
84 | |||
79 | router.get('/static-route', async (req, res) => { | 85 | router.get('/static-route', async (req, res) => { |
80 | const staticRoute = peertubeHelpers.plugin.getBaseStaticRoute() | 86 | const staticRoute = peertubeHelpers.plugin.getBaseStaticRoute() |
81 | 87 | ||
diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts index 038e3f0d6..e25992723 100644 --- a/server/tests/plugins/plugin-helpers.ts +++ b/server/tests/plugins/plugin-helpers.ts | |||
@@ -64,6 +64,18 @@ describe('Test plugin helpers', function () { | |||
64 | await servers[0].servers.waitUntilLog(`server url is ${servers[0].url}`) | 64 | await servers[0].servers.waitUntilLog(`server url is ${servers[0].url}`) |
65 | }) | 65 | }) |
66 | 66 | ||
67 | it('Should have the correct listening config', async function () { | ||
68 | const res = await makeGetRequest({ | ||
69 | url: servers[0].url, | ||
70 | path: '/plugins/test-four/router/server-listening-config', | ||
71 | expectedStatus: HttpStatusCode.OK_200 | ||
72 | }) | ||
73 | |||
74 | expect(res.body.config).to.exist | ||
75 | expect(res.body.config.hostname).to.equal('::') | ||
76 | expect(res.body.config.port).to.equal(servers[0].port) | ||
77 | }) | ||
78 | |||
67 | it('Should have the correct config', async function () { | 79 | it('Should have the correct config', async function () { |
68 | const res = await makeGetRequest({ | 80 | const res = await makeGetRequest({ |
69 | url: servers[0].url, | 81 | url: servers[0].url, |
diff --git a/server/types/plugins/register-server-option.model.ts b/server/types/plugins/register-server-option.model.ts index 1e2bd830e..df419fff4 100644 --- a/server/types/plugins/register-server-option.model.ts +++ b/server/types/plugins/register-server-option.model.ts | |||
@@ -71,6 +71,9 @@ export type PeerTubeHelpers = { | |||
71 | config: { | 71 | config: { |
72 | getWebserverUrl: () => string | 72 | getWebserverUrl: () => string |
73 | 73 | ||
74 | // PeerTube >= 5.1 | ||
75 | getServerListeningConfig: () => { hostname: string, port: number } | ||
76 | |||
74 | getServerConfig: () => Promise<ServerConfig> | 77 | getServerConfig: () => Promise<ServerConfig> |
75 | } | 78 | } |
76 | 79 | ||