1
0
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:
Ivar Conradi Østhus 2020-12-17 19:43:01 +01:00
parent 97b2c4985b
commit 79fc089a35
6 changed files with 53 additions and 29 deletions

View File

@ -15,7 +15,7 @@ const simpleAuthentication = require('./middleware/simple-authentication');
const noAuthentication = require('./middleware/no-authentication');
const secureHeaders = require('./middleware/secure-headers');
module.exports = function(config) {
module.exports = function(config, services = {}) {
const app = express();
const baseUriPath = config.baseUriPath || '';
@ -60,7 +60,7 @@ module.exports = function(config) {
}
// Setup API routes
app.use(`${baseUriPath}/`, new IndexRouter(config).router);
app.use(`${baseUriPath}/`, new IndexRouter(config, services).router);
if (process.env.NODE_ENV !== 'production') {
app.use(errorHandler());

View File

@ -14,23 +14,41 @@ const StateController = require('./state');
const apiDef = require('./api-def.json');
class AdminApi extends Controller {
constructor(config) {
constructor(config, services) {
super(config);
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(
'/feature-types',
new FeatureTypeController(config).router,
new FeatureTypeController(config, services).router,
);
this.app.use('/archive', new ArchiveController(config).router);
this.app.use('/strategies', new StrategyController(config).router);
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);
this.app.use('/context', new ContextController(config).router);
this.app.use('/state', new StateController(config).router);
this.app.use(
'/archive',
new ArchiveController(config, services).router,
);
this.app.use(
'/strategies',
new StrategyController(config, services).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) {

View File

@ -12,9 +12,10 @@ const { handleErrors } = require('./util');
const upload = multer({ limits: { fileSize: 5242880 } });
class StateController extends Controller {
constructor(config) {
constructor(config, services) {
super(config);
this.logger = config.getLogger('/admin-api/state.js');
this.stateService = services.stateService;
this.fileupload('/import', upload.single('file'), this.import, ADMIN);
this.get('/export', this.export, ADMIN);
}
@ -35,7 +36,7 @@ class StateController extends Controller {
data = req.body;
}
await this.config.stateService.import({
await this.stateService.import({
data,
userName,
dropBeforeImport: drop,
@ -61,7 +62,7 @@ class StateController extends Controller {
}
try {
const data = await this.config.stateService.export({
const data = await this.stateService.export({
includeStrategies,
includeFeatureToggles,
});

View File

@ -11,14 +11,14 @@ const LogoutController = require('./logout');
const api = require('./api-def');
class IndexRouter extends Controller {
constructor(config) {
constructor(config, services) {
super();
this.use('/health', new HealthCheckController(config).router);
this.use('/internal-backstage', new BackstageCTR(config).router);
this.use('/logout', new LogoutController(config).router);
this.get(api.uri, this.index);
this.use(api.links.admin.uri, new AdminApi(config).router);
this.use(api.links.client.uri, new ClientApi(config).router);
this.use(api.links.admin.uri, new AdminApi(config, services).router);
this.use(api.links.client.uri, new ClientApi(config, services).router);
// legacy support (remove in 4.x)
if (config.enableLegacyRoutes) {

View File

@ -53,7 +53,7 @@ async function createApp(options) {
...options,
};
const app = getApp(config);
const app = getApp(config, services);
const metricsMonitor = createMetricsMonitor();
metricsMonitor.startMonitoring(config);

View File

@ -12,16 +12,21 @@ const StateService = require('../../../lib/services/state-service');
const eventBus = new EventEmitter();
function createApp(stores, adminAuthentication = 'none', preHook) {
return getApp({
stores,
eventBus,
preHook,
adminAuthentication,
secret: 'super-secret',
sessionAge: 4000,
const services = {
stateService: new StateService(stores, { getLogger }),
getLogger,
});
};
return getApp(
{
stores,
eventBus,
preHook,
adminAuthentication,
secret: 'super-secret',
sessionAge: 4000,
getLogger,
},
services,
);
}
module.exports = {