mirror of https://github.com/Chocobozzz/PeerTube
Server: add config endpoint
parent
a2457e9de4
commit
e22528aca6
|
@ -25,3 +25,6 @@ storage:
|
|||
|
||||
admin:
|
||||
email: 'admin@example.com'
|
||||
|
||||
signup:
|
||||
enabled: false
|
||||
|
|
|
@ -26,3 +26,6 @@ storage:
|
|||
|
||||
admin:
|
||||
email: 'admin@example.com'
|
||||
|
||||
signup:
|
||||
enabled: false
|
||||
|
|
|
@ -7,3 +7,6 @@ webserver:
|
|||
database:
|
||||
hostname: 'localhost'
|
||||
port: 5432
|
||||
|
||||
signup:
|
||||
enabled: true
|
||||
|
|
|
@ -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
|
|
@ -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)
|
||||
|
|
|
@ -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 = []
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
})
|
||||
})
|
|
@ -1,6 +1,7 @@
|
|||
'use strict'
|
||||
|
||||
// Order of the tests we want to execute
|
||||
require('./config')
|
||||
require('./check-params')
|
||||
require('./friends-basic')
|
||||
require('./users')
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue