mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-19 00:15:43 +01:00
feat: add configuration option for disabling legacy api
This commit is contained in:
parent
979d7862db
commit
a3e448a1bc
@ -287,6 +287,10 @@ export function createConfig(options: IUnleashOptions): IUnleashConfig {
|
||||
const enableOAS =
|
||||
options.enableOAS || safeBoolean(process.env.ENABLE_OAS, false);
|
||||
|
||||
const disableLegacyFeaturesApi =
|
||||
options.disableLegacyFeaturesApi ||
|
||||
safeBoolean(process.env.DISABLE_LEGACY_FEATURES_API, false);
|
||||
|
||||
return {
|
||||
db,
|
||||
session,
|
||||
@ -301,6 +305,7 @@ export function createConfig(options: IUnleashOptions): IUnleashConfig {
|
||||
email,
|
||||
secureHeaders,
|
||||
enableOAS,
|
||||
disableLegacyFeaturesApi,
|
||||
preHook: options.preHook,
|
||||
preRouterHook: options.preRouterHook,
|
||||
eventHook: options.eventHook,
|
||||
|
@ -30,10 +30,14 @@ class AdminApi extends Controller {
|
||||
super(config);
|
||||
|
||||
this.app.get('/', this.index);
|
||||
this.app.use(
|
||||
'/features',
|
||||
new FeatureController(config, services).router,
|
||||
);
|
||||
|
||||
if (!config.disableLegacyFeaturesApi) {
|
||||
this.app.use(
|
||||
'/features',
|
||||
new FeatureController(config, services).router,
|
||||
);
|
||||
}
|
||||
|
||||
this.app.use(
|
||||
'/feature-types',
|
||||
new FeatureTypeController(config, services).router,
|
||||
|
@ -101,6 +101,7 @@ export interface IUnleashOptions {
|
||||
preRouterHook?: Function;
|
||||
eventHook?: EventHook;
|
||||
enterpriseVersion?: string;
|
||||
disableLegacyFeaturesApi?: boolean;
|
||||
}
|
||||
|
||||
export interface IEmailOption {
|
||||
@ -156,4 +157,5 @@ export interface IUnleashConfig {
|
||||
eventHook?: EventHook;
|
||||
enterpriseVersion?: string;
|
||||
eventBus: EventEmitter;
|
||||
disableLegacyFeaturesApi?: boolean;
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
import faker from 'faker';
|
||||
import { FeatureToggleDTO, IStrategyConfig, IVariant } from 'lib/types/model';
|
||||
import dbInit, { ITestDb } from '../../helpers/database-init';
|
||||
import { IUnleashTest, setupApp } from '../../helpers/test-helper';
|
||||
import {
|
||||
IUnleashTest,
|
||||
setupApp,
|
||||
setupAppWithCustomConfig,
|
||||
} from '../../helpers/test-helper';
|
||||
import getLogger from '../../../fixtures/no-logger';
|
||||
import { DEFAULT_ENV } from '../../../../lib/util/constants';
|
||||
|
||||
@ -680,3 +684,21 @@ test('marks feature toggle as stale', async () => {
|
||||
expect(res.body.stale).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
test('should not hit endpoints if disable configuration is set', async () => {
|
||||
const appWithDisabledLegacyFeatures = await setupAppWithCustomConfig(
|
||||
db.stores,
|
||||
{
|
||||
disableLegacyFeaturesApi: true,
|
||||
},
|
||||
);
|
||||
|
||||
await appWithDisabledLegacyFeatures.request
|
||||
.get('/api/admin/features')
|
||||
.expect(404);
|
||||
|
||||
return appWithDisabledLegacyFeatures.request
|
||||
.get('/api/admin/features/featureX')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(404);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user