2021-04-22 10:07:10 +02:00
|
|
|
import { Request, Response } from 'express';
|
|
|
|
import { IUnleashServices } from '../../types/services';
|
|
|
|
import { IUnleashConfig } from '../../types/option';
|
|
|
|
import version from '../../util/version';
|
|
|
|
|
2019-03-12 10:46:08 +01:00
|
|
|
const Controller = require('../controller');
|
|
|
|
|
|
|
|
class ConfigController extends Controller {
|
2021-04-22 10:07:10 +02:00
|
|
|
constructor(
|
|
|
|
config: IUnleashConfig,
|
|
|
|
{ versionService }: Pick<IUnleashServices, 'versionService'>,
|
|
|
|
) {
|
2019-03-12 10:46:08 +01:00
|
|
|
super(config);
|
2021-02-19 11:13:25 +01:00
|
|
|
this.versionService = versionService;
|
2021-04-15 11:35:45 +02:00
|
|
|
const authenticationType =
|
|
|
|
config.authentication && config.authentication.type;
|
2021-02-19 11:13:25 +01:00
|
|
|
this.uiConfig = {
|
|
|
|
...config.ui,
|
2021-04-15 11:29:53 +02:00
|
|
|
authenticationType,
|
2021-04-22 10:07:10 +02:00
|
|
|
unleashUrl: config.server.unleashUrl,
|
|
|
|
baseUriPath: config.server.baseUriPath,
|
|
|
|
version,
|
2021-02-19 11:13:25 +01:00
|
|
|
};
|
2019-03-12 10:46:08 +01:00
|
|
|
this.get('/', this.getUIConfig);
|
|
|
|
}
|
|
|
|
|
2021-04-22 10:07:10 +02:00
|
|
|
async getUIConfig(req: Request, res: Response): Promise<void> {
|
2019-03-12 10:46:08 +01:00
|
|
|
const config = this.uiConfig;
|
2021-02-19 11:13:25 +01:00
|
|
|
if (this.versionService) {
|
|
|
|
const versionInfo = this.versionService.getVersionInfo();
|
|
|
|
res.json({ ...config, versionInfo });
|
|
|
|
} else {
|
|
|
|
res.json(config);
|
|
|
|
}
|
2019-03-12 10:46:08 +01:00
|
|
|
}
|
|
|
|
}
|
2021-04-22 10:07:10 +02:00
|
|
|
export default ConfigController;
|
2019-03-12 10:46:08 +01:00
|
|
|
module.exports = ConfigController;
|