diff --git a/docs/getting-started.md b/docs/getting-started.md index 71b125b045..9abd785a94 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -55,6 +55,7 @@ Available unleash options include: - `none` - will disable authentication altogether - `unsecure` - (default) will use simple cookie based authentication. UI will require the user to specify an email in order to use unleash. - `custom` - use this when you implement your own custom authentication logic. +- **ui** (object) - Set of UI specific overrides. You may set the following keys: `headerBackground`, `environment`, `slogan`. ### 3. Docker diff --git a/lib/options.js b/lib/options.js index 3fffbd8e65..bebaae6173 100644 --- a/lib/options.js +++ b/lib/options.js @@ -19,6 +19,7 @@ const DEFAULT_OPTIONS = { secret: 'UNLEASH-SECRET', sessionAge: THIRTY_DAYS, adminAuthentication: 'unsecure', + ui: {}, }; module.exports = { @@ -36,6 +37,7 @@ module.exports = { 'You must either pass databaseUrl option or set environemnt variable DATABASE_URL' ); } + return options; }, }; diff --git a/lib/routes/admin-api/config.js b/lib/routes/admin-api/config.js new file mode 100644 index 0000000000..6d2e068dd1 --- /dev/null +++ b/lib/routes/admin-api/config.js @@ -0,0 +1,19 @@ +'use strict'; + +const Controller = require('../controller'); + +class ConfigController extends Controller { + constructor(config) { + super(config); + this.uiConfig = config.ui; + + this.get('/', this.getUIConfig); + } + + async getUIConfig(req, res) { + const config = this.uiConfig; + res.json(config); + } +} + +module.exports = ConfigController; diff --git a/lib/routes/admin-api/config.test.js b/lib/routes/admin-api/config.test.js new file mode 100644 index 0000000000..c7355098f0 --- /dev/null +++ b/lib/routes/admin-api/config.test.js @@ -0,0 +1,44 @@ +'use strict'; + +const test = require('ava'); +const store = require('./../../../test/fixtures/store'); +const supertest = require('supertest'); +const getApp = require('../../app'); + +const { EventEmitter } = require('events'); +const eventBus = new EventEmitter(); + +const uiConfig = { + headerBackground: 'red', + slogan: 'hello', +}; + +function getSetup() { + const base = `/random${Math.round(Math.random() * 1000)}`; + const stores = store.createStores(); + const app = getApp({ + baseUriPath: base, + stores, + eventBus, + extendedPermissions: false, + ui: uiConfig, + }); + + return { + base, + request: supertest(app), + }; +} + +test('should get ui config', t => { + t.plan(2); + const { request, base } = getSetup(); + return request + .get(`${base}/api/admin/ui-config`) + .expect('Content-Type', /json/) + .expect(200) + .expect(res => { + t.true(res.body.slogan === 'hello'); + t.true(res.body.headerBackground === 'red'); + }); +}); diff --git a/lib/routes/admin-api/index.js b/lib/routes/admin-api/index.js index a5af241638..16de70e4d2 100644 --- a/lib/routes/admin-api/index.js +++ b/lib/routes/admin-api/index.js @@ -7,6 +7,7 @@ const EventController = require('./event.js'); const StrategyController = require('./strategy'); const MetricsController = require('./metrics'); const UserController = require('./user'); +const ConfigController = require('./config'); const apiDef = require('./api-def.json'); class AdminApi extends Controller { @@ -20,6 +21,7 @@ class AdminApi extends Controller { this.app.use('/events', new EventController(config).router); this.app.use('/metrics', new MetricsController(config).router); this.app.use('/user', new UserController(config).router); + this.app.use('/ui-config', new ConfigController(config).router); } index(req, res) { diff --git a/package.json b/package.json index bb3cf5bf58..cca89bd54f 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "prometheus-gc-stats": "^0.6.1", "response-time": "^2.3.2", "serve-favicon": "^2.5.0", - "unleash-frontend": "3.2.1", + "unleash-frontend": "3.2.2", "yallist": "^3.0.3", "yargs": "^13.2.1" }, diff --git a/yarn.lock b/yarn.lock index d45832e641..644a87badb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5959,10 +5959,10 @@ universalify@^0.1.0: resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== -unleash-frontend@3.2.1: - version "3.2.1" - resolved "https://registry.yarnpkg.com/unleash-frontend/-/unleash-frontend-3.2.1.tgz#d82e18841eb8d53107eb82b512738ccfed51ffba" - integrity sha512-O/ckWWfFHqJN4Vt0w3YuacEIgeukFWj2iKH2dPRyLkjOjykvjHD8MyWdD6AnhVwdI3IRUWpJNvQjd5y7JX9gxw== +unleash-frontend@3.2.2: + version "3.2.2" + resolved "https://registry.yarnpkg.com/unleash-frontend/-/unleash-frontend-3.2.2.tgz#0c43c291a3fa584710ebc28f5dce00af6f54256d" + integrity sha512-jbYPn38l7q+2L23X/UYmpuYcgnuhfQ++gA1r0rFeVF202zKgtXlNTKp4grRvDDv/rxMWe05t8UjtVoRkL93p8Q== unpipe@1.0.0, unpipe@~1.0.0: version "1.0.0"