Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Server: add config endpoint

Chocobozzze22528aca6eb
diff --git a/config/default.yaml b/config/default.yaml
index 172bbef1e3..a5ac157945 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -25,3 +25,6 @@ storage:
admin:
+
+signup:
+ enabled: false
diff --git a/config/production.yaml.example b/config/production.yaml.example
index cbfb0f46ce..8e9d4b32d2 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -26,3 +26,6 @@ storage:
admin:
+
+signup:
+ enabled: false
diff --git a/config/test.yaml b/config/test.yaml
index 493a230764..1a08d5ed1f 100644
--- a/config/test.yaml
+++ b/config/test.yaml
@@ -7,3 +7,6 @@ webserver:
database:
hostname: 'localhost'
port: 5432
+
+signup:
+ enabled: true
diff --git a/server/controllers/api/config.js b/server/controllers/api/config.js
new file mode 100644
index 0000000000..8154b6ad0e
--- /dev/null
+++ b/server/controllers/api/config.js
@@ -0,0 +1,22 @@
+'use strict'
+
+const express = require('express')
+
+const constants = require('../../initializers/constants')
+
+const router = express.Router()
+
+router.get('/', getConfig)
+
+// Get the client credentials for the PeerTube front end
+function getConfig (req, res, next) {
+ res.json({
+ signup: {
+ enabled: constants.CONFIG.SIGNUP.ENABLED
+ }
+ })
+}
+
+// ---------------------------------------------------------------------------
+
+module.exports = router
diff --git a/server/controllers/api/index.js b/server/controllers/api/index.js
index f13ff922c9..6edc089f46 100644
--- a/server/controllers/api/index.js
+++ b/server/controllers/api/index.js
@@ -7,6 +7,7 @@ const utils = require('../../helpers/utils')
const router = express.Router()
const clientsController = require('./clients')
+const configController = require('./config')
const podsController = require('./pods')
const remoteController = require('./remote')
const requestsController = require('./requests')
@@ -14,6 +15,7 @@ const usersController = require('./users')
const videosController = require('./videos')
router.use('/clients', clientsController)
+router.use('/config', configController)
router.use('/pods', podsController)
router.use('/remote', remoteController)
router.use('/requests', requestsController)
diff --git a/server/initializers/checker.js b/server/initializers/checker.js
index 7adbbb37a2..461a851fec 100644
--- a/server/initializers/checker.js
+++ b/server/initializers/checker.js
@@ -29,7 +29,7 @@ function checkMissedConfig () {
'webserver.https', 'webserver.hostname', 'webserver.port',
'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password',
'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews',
- 'admin.email'
+ 'admin.email', 'signup.enabled'
]
const miss = []
diff --git a/server/initializers/constants.js b/server/initializers/constants.js
index f9247e9450..96321b2110 100644
--- a/server/initializers/constants.js
+++ b/server/initializers/constants.js
@@ -61,6 +61,9 @@ const CONFIG = {
},
ADMIN: {
EMAIL: config.get('admin.email')
+ },
+ SIGNUP: {
+ ENABLED: config.get('signup.enabled')
}
}
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 0000000000..08f955f2d0
--- /dev/null
+++ b/server/tests/api/config.js
@@ -0,0 +1,53 @@
+/* eslint-disable no-unused-expressions */
+
+'use strict'
+
+const chai = require('chai')
+const expect = chai.expect
+const series = require('async/series')
+
+const serversUtils = require('../utils/servers')
+const configUtils = require('../utils/config')
+
+describe('Test config', function () {
+ let server = null
+
+ before(function (done) {
+ this.timeout(20000)
+
+ series([
+ function (next) {
+ serversUtils.flushTests(next)
+ },
+ function (next) {
+ serversUtils.runServer(1, function (server1) {
+ server = server1
+ next()
+ })
+ }
+ ], done)
+ })
+
+ it('Should have a correct config', function (done) {
+ configUtils.getConfig(server.url, function (err, res) {
+ if (err) throw err
+
+ const data = res.body
+
+ expect(data.signup.enabled).to.be.truthy
+
+ done()
+ })
+ })
+
+ after(function (done) {
+ process.kill(-server.app.pid)
+
+ // Keep the logs if the test failed
+ if (this.ok) {
+ serversUtils.flushTests(done)
+ } else {
+ done()
+ }
+ })
+})
diff --git a/server/tests/api/index.js b/server/tests/api/index.js
index 11f49e1e2c..dc6ef92ab1 100644
--- a/server/tests/api/index.js
+++ b/server/tests/api/index.js
@@ -1,6 +1,7 @@
'use strict'
// Order of the tests we want to execute
+require('./config')
require('./check-params')
require('./friends-basic')
require('./users')
diff --git a/server/tests/utils/config.js b/server/tests/utils/config.js
new file mode 100644
index 0000000000..0a507a60fc
--- /dev/null
+++ b/server/tests/utils/config.js
@@ -0,0 +1,24 @@
+'use strict'
+
+const request = require('supertest')
+
+const configsUtils = {
+ getConfig
+}
+
+// ---------------------- Export functions --------------------
+
+function getConfig (url, end) {
+ const path = '/api/v1/config'
+
+ request(url)
+ .get(path)
+ .set('Accept', 'application/json')
+ .expect(200)
+ .expect('Content-Type', /json/)
+ .end(end)
+}
+
+// ---------------------------------------------------------------------------
+
+module.exports = configsUtils