Server: add config endpoint
authorChocobozzz <florian.bigard@gmail.com>
Fri, 10 Mar 2017 10:32:39 +0000 (11:32 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Fri, 10 Mar 2017 10:32:39 +0000 (11:32 +0100)
config/default.yaml
config/production.yaml.example
config/test.yaml
server/controllers/api/config.js [new file with mode: 0644]
server/controllers/api/index.js
server/initializers/checker.js
server/initializers/constants.js
server/tests/api/config.js [new file with mode: 0644]
server/tests/api/index.js
server/tests/utils/config.js [new file with mode: 0644]

index 172bbef1e3284f3bc63fb02edb5e706bd88ea169..a5ac157945d22990462b314ca562eef9bb530dec 100644 (file)
@@ -25,3 +25,6 @@ storage:
 
 admin:
   email: 'admin@example.com'
+
+signup:
+  enabled: false
index cbfb0f46ce4a6ad28f7d78e16a3275fb733f70d3..8e9d4b32d20b5c88f1b2be5603487c12a6884b1d 100644 (file)
@@ -26,3 +26,6 @@ storage:
 
 admin:
   email: 'admin@example.com'
+
+signup:
+  enabled: false
index 493a23076485ff2a26c4919d47d839b7fd8788d9..1a08d5ed1f011348deecd9b1423d4cd1b629a150 100644 (file)
@@ -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 (file)
index 0000000..8154b6a
--- /dev/null
@@ -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
index f13ff922c949804c9a654345f5f2a952b110a58f..6edc089f46e0da0899cab81741cd294af0baa734 100644 (file)
@@ -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)
index 7adbbb37a2569600328f70343150bfc12029f481..461a851fecf2c9f1e14414a5a0224f5815fbda2e 100644 (file)
@@ -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 = []
 
index f9247e9450cab909e9b85669e83ccc2df54c69ea..96321b211041e91885e2b39074d31f2a6567a3df 100644 (file)
@@ -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 (file)
index 0000000..08f955f
--- /dev/null
@@ -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()
+    }
+  })
+})
index 11f49e1e2cc3486811c9dfaa56f8ebf49f9ffc36..dc6ef92ab133027c7e07c9e0761076396c81daf8 100644 (file)
@@ -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 (file)
index 0000000..0a507a6
--- /dev/null
@@ -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