diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-03-10 11:32:39 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-03-10 11:32:39 +0100 |
commit | e22528aca6eb58c8f8005790ac6e76ed4f8ad706 (patch) | |
tree | 9669efb759249438e2b065171f19f817f7d48440 | |
parent | a2457e9de4a598ea34629bc40eb882ce03ec0ede (diff) | |
download | PeerTube-e22528aca6eb58c8f8005790ac6e76ed4f8ad706.tar.gz PeerTube-e22528aca6eb58c8f8005790ac6e76ed4f8ad706.tar.zst PeerTube-e22528aca6eb58c8f8005790ac6e76ed4f8ad706.zip |
Server: add config endpoint
-rw-r--r-- | config/default.yaml | 3 | ||||
-rw-r--r-- | config/production.yaml.example | 3 | ||||
-rw-r--r-- | config/test.yaml | 3 | ||||
-rw-r--r-- | server/controllers/api/config.js | 22 | ||||
-rw-r--r-- | server/controllers/api/index.js | 2 | ||||
-rw-r--r-- | server/initializers/checker.js | 2 | ||||
-rw-r--r-- | server/initializers/constants.js | 3 | ||||
-rw-r--r-- | server/tests/api/config.js | 53 | ||||
-rw-r--r-- | server/tests/api/index.js | 1 | ||||
-rw-r--r-- | server/tests/utils/config.js | 24 |
10 files changed, 115 insertions, 1 deletions
diff --git a/config/default.yaml b/config/default.yaml index 172bbef1e..a5ac15794 100644 --- a/config/default.yaml +++ b/config/default.yaml | |||
@@ -25,3 +25,6 @@ storage: | |||
25 | 25 | ||
26 | admin: | 26 | admin: |
27 | email: 'admin@example.com' | 27 | email: 'admin@example.com' |
28 | |||
29 | signup: | ||
30 | enabled: false | ||
diff --git a/config/production.yaml.example b/config/production.yaml.example index cbfb0f46c..8e9d4b32d 100644 --- a/config/production.yaml.example +++ b/config/production.yaml.example | |||
@@ -26,3 +26,6 @@ storage: | |||
26 | 26 | ||
27 | admin: | 27 | admin: |
28 | email: 'admin@example.com' | 28 | email: 'admin@example.com' |
29 | |||
30 | signup: | ||
31 | enabled: false | ||
diff --git a/config/test.yaml b/config/test.yaml index 493a23076..1a08d5ed1 100644 --- a/config/test.yaml +++ b/config/test.yaml | |||
@@ -7,3 +7,6 @@ webserver: | |||
7 | database: | 7 | database: |
8 | hostname: 'localhost' | 8 | hostname: 'localhost' |
9 | port: 5432 | 9 | port: 5432 |
10 | |||
11 | signup: | ||
12 | enabled: true | ||
diff --git a/server/controllers/api/config.js b/server/controllers/api/config.js new file mode 100644 index 000000000..8154b6ad0 --- /dev/null +++ b/server/controllers/api/config.js | |||
@@ -0,0 +1,22 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const express = require('express') | ||
4 | |||
5 | const constants = require('../../initializers/constants') | ||
6 | |||
7 | const router = express.Router() | ||
8 | |||
9 | router.get('/', getConfig) | ||
10 | |||
11 | // Get the client credentials for the PeerTube front end | ||
12 | function getConfig (req, res, next) { | ||
13 | res.json({ | ||
14 | signup: { | ||
15 | enabled: constants.CONFIG.SIGNUP.ENABLED | ||
16 | } | ||
17 | }) | ||
18 | } | ||
19 | |||
20 | // --------------------------------------------------------------------------- | ||
21 | |||
22 | module.exports = router | ||
diff --git a/server/controllers/api/index.js b/server/controllers/api/index.js index f13ff922c..6edc089f4 100644 --- a/server/controllers/api/index.js +++ b/server/controllers/api/index.js | |||
@@ -7,6 +7,7 @@ const utils = require('../../helpers/utils') | |||
7 | const router = express.Router() | 7 | const router = express.Router() |
8 | 8 | ||
9 | const clientsController = require('./clients') | 9 | const clientsController = require('./clients') |
10 | const configController = require('./config') | ||
10 | const podsController = require('./pods') | 11 | const podsController = require('./pods') |
11 | const remoteController = require('./remote') | 12 | const remoteController = require('./remote') |
12 | const requestsController = require('./requests') | 13 | const requestsController = require('./requests') |
@@ -14,6 +15,7 @@ const usersController = require('./users') | |||
14 | const videosController = require('./videos') | 15 | const videosController = require('./videos') |
15 | 16 | ||
16 | router.use('/clients', clientsController) | 17 | router.use('/clients', clientsController) |
18 | router.use('/config', configController) | ||
17 | router.use('/pods', podsController) | 19 | router.use('/pods', podsController) |
18 | router.use('/remote', remoteController) | 20 | router.use('/remote', remoteController) |
19 | router.use('/requests', requestsController) | 21 | router.use('/requests', requestsController) |
diff --git a/server/initializers/checker.js b/server/initializers/checker.js index 7adbbb37a..461a851fe 100644 --- a/server/initializers/checker.js +++ b/server/initializers/checker.js | |||
@@ -29,7 +29,7 @@ function checkMissedConfig () { | |||
29 | 'webserver.https', 'webserver.hostname', 'webserver.port', | 29 | 'webserver.https', 'webserver.hostname', 'webserver.port', |
30 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', | 30 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', |
31 | 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews', | 31 | 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews', |
32 | 'admin.email' | 32 | 'admin.email', 'signup.enabled' |
33 | ] | 33 | ] |
34 | const miss = [] | 34 | const miss = [] |
35 | 35 | ||
diff --git a/server/initializers/constants.js b/server/initializers/constants.js index f9247e945..96321b211 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.js | |||
@@ -61,6 +61,9 @@ const CONFIG = { | |||
61 | }, | 61 | }, |
62 | ADMIN: { | 62 | ADMIN: { |
63 | EMAIL: config.get('admin.email') | 63 | EMAIL: config.get('admin.email') |
64 | }, | ||
65 | SIGNUP: { | ||
66 | ENABLED: config.get('signup.enabled') | ||
64 | } | 67 | } |
65 | } | 68 | } |
66 | CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT | 69 | CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT |
diff --git a/server/tests/api/config.js b/server/tests/api/config.js new file mode 100644 index 000000000..08f955f2d --- /dev/null +++ b/server/tests/api/config.js | |||
@@ -0,0 +1,53 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const chai = require('chai') | ||
6 | const expect = chai.expect | ||
7 | const series = require('async/series') | ||
8 | |||
9 | const serversUtils = require('../utils/servers') | ||
10 | const configUtils = require('../utils/config') | ||
11 | |||
12 | describe('Test config', function () { | ||
13 | let server = null | ||
14 | |||
15 | before(function (done) { | ||
16 | this.timeout(20000) | ||
17 | |||
18 | series([ | ||
19 | function (next) { | ||
20 | serversUtils.flushTests(next) | ||
21 | }, | ||
22 | function (next) { | ||
23 | serversUtils.runServer(1, function (server1) { | ||
24 | server = server1 | ||
25 | next() | ||
26 | }) | ||
27 | } | ||
28 | ], done) | ||
29 | }) | ||
30 | |||
31 | it('Should have a correct config', function (done) { | ||
32 | configUtils.getConfig(server.url, function (err, res) { | ||
33 | if (err) throw err | ||
34 | |||
35 | const data = res.body | ||
36 | |||
37 | expect(data.signup.enabled).to.be.truthy | ||
38 | |||
39 | done() | ||
40 | }) | ||
41 | }) | ||
42 | |||
43 | after(function (done) { | ||
44 | process.kill(-server.app.pid) | ||
45 | |||
46 | // Keep the logs if the test failed | ||
47 | if (this.ok) { | ||
48 | serversUtils.flushTests(done) | ||
49 | } else { | ||
50 | done() | ||
51 | } | ||
52 | }) | ||
53 | }) | ||
diff --git a/server/tests/api/index.js b/server/tests/api/index.js index 11f49e1e2..dc6ef92ab 100644 --- a/server/tests/api/index.js +++ b/server/tests/api/index.js | |||
@@ -1,6 +1,7 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | // Order of the tests we want to execute | 3 | // Order of the tests we want to execute |
4 | require('./config') | ||
4 | require('./check-params') | 5 | require('./check-params') |
5 | require('./friends-basic') | 6 | require('./friends-basic') |
6 | require('./users') | 7 | require('./users') |
diff --git a/server/tests/utils/config.js b/server/tests/utils/config.js new file mode 100644 index 000000000..0a507a60f --- /dev/null +++ b/server/tests/utils/config.js | |||
@@ -0,0 +1,24 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const request = require('supertest') | ||
4 | |||
5 | const configsUtils = { | ||
6 | getConfig | ||
7 | } | ||
8 | |||
9 | // ---------------------- Export functions -------------------- | ||
10 | |||
11 | function getConfig (url, end) { | ||
12 | const path = '/api/v1/config' | ||
13 | |||
14 | request(url) | ||
15 | .get(path) | ||
16 | .set('Accept', 'application/json') | ||
17 | .expect(200) | ||
18 | .expect('Content-Type', /json/) | ||
19 | .end(end) | ||
20 | } | ||
21 | |||
22 | // --------------------------------------------------------------------------- | ||
23 | |||
24 | module.exports = configsUtils | ||