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:
parent
529ac38e97
commit
4ea00e4b7e
@ -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' });
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user