1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00

chore: Simplify client-controller constructor

This commit is contained in:
ivaosthu 2018-11-29 21:01:53 +01:00 committed by Ivar Conradi Østhus
parent 529ac38e97
commit 4ea00e4b7e
5 changed files with 15 additions and 10 deletions

View File

@ -6,10 +6,10 @@ const { filter } = require('./util');
const version = 1;
class FeatureController {
constructor(config) {
constructor({ featureToggleStore }) {
const router = Router();
this._router = router;
this.store = config.stores.featureToggleStore;
this.toggleStore = featureToggleStore;
router.get('/', (req, res) => this.getAll(req, res));
router.get('/:featureName', this.getFeatureToggle.bind(this));
@ -18,7 +18,7 @@ class FeatureController {
async getAll(req, res) {
const nameFilter = filter('name', req.query.namePrefix);
const allFeatureToggles = await this.store.getFeatures();
const allFeatureToggles = await this.toggleStore.getFeatures();
const features = nameFilter(allFeatureToggles);
res.json({ version, features });
@ -27,7 +27,7 @@ class FeatureController {
async getFeatureToggle(req, res) {
try {
const name = req.params.featureName;
const featureToggle = await this.store.getFeature(name);
const featureToggle = await this.toggleStore.getFeature(name);
res.json(featureToggle).end();
} catch (err) {
res.status(404).json({ error: 'Could not find feature' });

View File

@ -11,10 +11,12 @@ class ClientApi {
const router = Router();
this._router = router;
const stores = config.stores;
router.get('/', this.index);
router.use('/features', new FeatureController(config).router());
router.use('/metrics', new MetricsController(config).router());
router.use('/register', new RegisterController(config).router());
router.use('/features', new FeatureController(stores).router());
router.use('/metrics', new MetricsController(stores).router());
router.use('/register', new RegisterController(stores).router());
}
index(req, res) {

View File

@ -7,7 +7,7 @@ const logger = require('../../logger')('client-api/metrics.js');
const { clientMetricsSchema } = require('./metrics-schema');
class ClientMetricsController {
constructor({ stores: { clientMetricsStore, clientInstanceStore } }) {
constructor({ clientMetricsStore, clientInstanceStore }) {
const router = Router();
this.clientMetricsStore = clientMetricsStore;
this.clientInstanceStore = clientInstanceStore;

View File

@ -7,7 +7,7 @@ const logger = require('../../logger')('/client-api/register.js');
const { clientRegisterSchema: schema } = require('./register-schema');
class RegisterController {
constructor({ stores: { clientInstanceStore, clientApplicationsStore } }) {
constructor({ clientInstanceStore, clientApplicationsStore }) {
const router = Router();
this._router = router;
this.clientInstanceStore = clientInstanceStore;

View File

@ -29,7 +29,10 @@ class IndexRouter {
// legacy support (remove in 4.x)
if (config.enableLegacyRoutes) {
router.use('/api/features', new FeatureController(config).router());
router.use(
'/api/features',
new FeatureController(config.stores).router()
);
}
}