mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
fix: stateService undefined
This commit is contained in:
parent
97b2c4985b
commit
79fc089a35
@ -15,7 +15,7 @@ const simpleAuthentication = require('./middleware/simple-authentication');
|
|||||||
const noAuthentication = require('./middleware/no-authentication');
|
const noAuthentication = require('./middleware/no-authentication');
|
||||||
const secureHeaders = require('./middleware/secure-headers');
|
const secureHeaders = require('./middleware/secure-headers');
|
||||||
|
|
||||||
module.exports = function(config) {
|
module.exports = function(config, services = {}) {
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
const baseUriPath = config.baseUriPath || '';
|
const baseUriPath = config.baseUriPath || '';
|
||||||
@ -60,7 +60,7 @@ module.exports = function(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setup API routes
|
// Setup API routes
|
||||||
app.use(`${baseUriPath}/`, new IndexRouter(config).router);
|
app.use(`${baseUriPath}/`, new IndexRouter(config, services).router);
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
app.use(errorHandler());
|
app.use(errorHandler());
|
||||||
|
@ -14,23 +14,41 @@ const StateController = require('./state');
|
|||||||
const apiDef = require('./api-def.json');
|
const apiDef = require('./api-def.json');
|
||||||
|
|
||||||
class AdminApi extends Controller {
|
class AdminApi extends Controller {
|
||||||
constructor(config) {
|
constructor(config, services) {
|
||||||
super(config);
|
super(config);
|
||||||
|
|
||||||
this.app.get('/', this.index);
|
this.app.get('/', this.index);
|
||||||
this.app.use('/features', new FeatureController(config).router);
|
this.app.use(
|
||||||
|
'/features',
|
||||||
|
new FeatureController(config, services).router,
|
||||||
|
);
|
||||||
this.app.use(
|
this.app.use(
|
||||||
'/feature-types',
|
'/feature-types',
|
||||||
new FeatureTypeController(config).router,
|
new FeatureTypeController(config, services).router,
|
||||||
);
|
);
|
||||||
this.app.use('/archive', new ArchiveController(config).router);
|
this.app.use(
|
||||||
this.app.use('/strategies', new StrategyController(config).router);
|
'/archive',
|
||||||
this.app.use('/events', new EventController(config).router);
|
new ArchiveController(config, services).router,
|
||||||
this.app.use('/metrics', new MetricsController(config).router);
|
);
|
||||||
this.app.use('/user', new UserController(config).router);
|
this.app.use(
|
||||||
this.app.use('/ui-config', new ConfigController(config).router);
|
'/strategies',
|
||||||
this.app.use('/context', new ContextController(config).router);
|
new StrategyController(config, services).router,
|
||||||
this.app.use('/state', new StateController(config).router);
|
);
|
||||||
|
this.app.use('/events', new EventController(config, services).router);
|
||||||
|
this.app.use(
|
||||||
|
'/metrics',
|
||||||
|
new MetricsController(config, services).router,
|
||||||
|
);
|
||||||
|
this.app.use('/user', new UserController(config, services).router);
|
||||||
|
this.app.use(
|
||||||
|
'/ui-config',
|
||||||
|
new ConfigController(config, services).router,
|
||||||
|
);
|
||||||
|
this.app.use(
|
||||||
|
'/context',
|
||||||
|
new ContextController(config, services).router,
|
||||||
|
);
|
||||||
|
this.app.use('/state', new StateController(config, services).router);
|
||||||
}
|
}
|
||||||
|
|
||||||
index(req, res) {
|
index(req, res) {
|
||||||
|
@ -12,9 +12,10 @@ const { handleErrors } = require('./util');
|
|||||||
const upload = multer({ limits: { fileSize: 5242880 } });
|
const upload = multer({ limits: { fileSize: 5242880 } });
|
||||||
|
|
||||||
class StateController extends Controller {
|
class StateController extends Controller {
|
||||||
constructor(config) {
|
constructor(config, services) {
|
||||||
super(config);
|
super(config);
|
||||||
this.logger = config.getLogger('/admin-api/state.js');
|
this.logger = config.getLogger('/admin-api/state.js');
|
||||||
|
this.stateService = services.stateService;
|
||||||
this.fileupload('/import', upload.single('file'), this.import, ADMIN);
|
this.fileupload('/import', upload.single('file'), this.import, ADMIN);
|
||||||
this.get('/export', this.export, ADMIN);
|
this.get('/export', this.export, ADMIN);
|
||||||
}
|
}
|
||||||
@ -35,7 +36,7 @@ class StateController extends Controller {
|
|||||||
data = req.body;
|
data = req.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.config.stateService.import({
|
await this.stateService.import({
|
||||||
data,
|
data,
|
||||||
userName,
|
userName,
|
||||||
dropBeforeImport: drop,
|
dropBeforeImport: drop,
|
||||||
@ -61,7 +62,7 @@ class StateController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await this.config.stateService.export({
|
const data = await this.stateService.export({
|
||||||
includeStrategies,
|
includeStrategies,
|
||||||
includeFeatureToggles,
|
includeFeatureToggles,
|
||||||
});
|
});
|
||||||
|
@ -11,14 +11,14 @@ const LogoutController = require('./logout');
|
|||||||
const api = require('./api-def');
|
const api = require('./api-def');
|
||||||
|
|
||||||
class IndexRouter extends Controller {
|
class IndexRouter extends Controller {
|
||||||
constructor(config) {
|
constructor(config, services) {
|
||||||
super();
|
super();
|
||||||
this.use('/health', new HealthCheckController(config).router);
|
this.use('/health', new HealthCheckController(config).router);
|
||||||
this.use('/internal-backstage', new BackstageCTR(config).router);
|
this.use('/internal-backstage', new BackstageCTR(config).router);
|
||||||
this.use('/logout', new LogoutController(config).router);
|
this.use('/logout', new LogoutController(config).router);
|
||||||
this.get(api.uri, this.index);
|
this.get(api.uri, this.index);
|
||||||
this.use(api.links.admin.uri, new AdminApi(config).router);
|
this.use(api.links.admin.uri, new AdminApi(config, services).router);
|
||||||
this.use(api.links.client.uri, new ClientApi(config).router);
|
this.use(api.links.client.uri, new ClientApi(config, services).router);
|
||||||
|
|
||||||
// legacy support (remove in 4.x)
|
// legacy support (remove in 4.x)
|
||||||
if (config.enableLegacyRoutes) {
|
if (config.enableLegacyRoutes) {
|
||||||
|
@ -53,7 +53,7 @@ async function createApp(options) {
|
|||||||
...options,
|
...options,
|
||||||
};
|
};
|
||||||
|
|
||||||
const app = getApp(config);
|
const app = getApp(config, services);
|
||||||
const metricsMonitor = createMetricsMonitor();
|
const metricsMonitor = createMetricsMonitor();
|
||||||
metricsMonitor.startMonitoring(config);
|
metricsMonitor.startMonitoring(config);
|
||||||
|
|
||||||
|
@ -12,16 +12,21 @@ const StateService = require('../../../lib/services/state-service');
|
|||||||
const eventBus = new EventEmitter();
|
const eventBus = new EventEmitter();
|
||||||
|
|
||||||
function createApp(stores, adminAuthentication = 'none', preHook) {
|
function createApp(stores, adminAuthentication = 'none', preHook) {
|
||||||
return getApp({
|
const services = {
|
||||||
|
stateService: new StateService(stores, { getLogger }),
|
||||||
|
};
|
||||||
|
return getApp(
|
||||||
|
{
|
||||||
stores,
|
stores,
|
||||||
eventBus,
|
eventBus,
|
||||||
preHook,
|
preHook,
|
||||||
adminAuthentication,
|
adminAuthentication,
|
||||||
secret: 'super-secret',
|
secret: 'super-secret',
|
||||||
sessionAge: 4000,
|
sessionAge: 4000,
|
||||||
stateService: new StateService(stores, { getLogger }),
|
|
||||||
getLogger,
|
getLogger,
|
||||||
});
|
},
|
||||||
|
services,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
Loading…
Reference in New Issue
Block a user