mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-10 17:53:36 +02:00
refactor: remove unused API definition routes
This commit is contained in:
parent
aebecf5f3a
commit
1ba5701422
@ -1,32 +0,0 @@
|
|||||||
{
|
|
||||||
"version": 3,
|
|
||||||
"links": {
|
|
||||||
"feature-toggles": {
|
|
||||||
"uri": "/api/admin/features"
|
|
||||||
},
|
|
||||||
"feature-archive": {
|
|
||||||
"uri": "/api/admin/archive"
|
|
||||||
},
|
|
||||||
"strategies": {
|
|
||||||
"uri": "/api/admin/strategies"
|
|
||||||
},
|
|
||||||
"events": {
|
|
||||||
"uri": "/api/admin/events"
|
|
||||||
},
|
|
||||||
"metrics": {
|
|
||||||
"uri": "/api/admin/metrics"
|
|
||||||
},
|
|
||||||
"state": {
|
|
||||||
"uri": "/api/admin/state"
|
|
||||||
},
|
|
||||||
"context": {
|
|
||||||
"uri": "/api/admin/context"
|
|
||||||
},
|
|
||||||
"tags": {
|
|
||||||
"uri": "/api/admin/tags"
|
|
||||||
},
|
|
||||||
"tag-types": {
|
|
||||||
"uri": "/api/admin/tag-types"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,3 @@
|
|||||||
import apiDef from './api-def.json';
|
|
||||||
import Controller from '../controller';
|
import Controller from '../controller';
|
||||||
import { IUnleashServices } from '../../types/services';
|
import { IUnleashServices } from '../../types/services';
|
||||||
import { IUnleashConfig } from '../../types/option';
|
import { IUnleashConfig } from '../../types/option';
|
||||||
@ -30,8 +29,6 @@ class AdminApi extends Controller {
|
|||||||
constructor(config: IUnleashConfig, services: IUnleashServices) {
|
constructor(config: IUnleashConfig, services: IUnleashServices) {
|
||||||
super(config);
|
super(config);
|
||||||
|
|
||||||
this.app.get('/', this.index);
|
|
||||||
|
|
||||||
this.app.use(
|
this.app.use(
|
||||||
'/features',
|
'/features',
|
||||||
new FeatureController(config, services).router,
|
new FeatureController(config, services).router,
|
||||||
@ -105,10 +102,6 @@ class AdminApi extends Controller {
|
|||||||
new ConstraintsController(config, services).router,
|
new ConstraintsController(config, services).router,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
index(req, res) {
|
|
||||||
res.json(apiDef);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = AdminApi;
|
module.exports = AdminApi;
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
import clientApiDef from './client-api/api-def.json';
|
|
||||||
import adminApiDef from './admin-api/api-def.json';
|
|
||||||
import version from '../util/version';
|
|
||||||
|
|
||||||
export const api = {
|
|
||||||
name: 'unleash-server',
|
|
||||||
version,
|
|
||||||
uri: '/api',
|
|
||||||
links: {
|
|
||||||
admin: {
|
|
||||||
uri: '/api/admin',
|
|
||||||
links: adminApiDef.links,
|
|
||||||
},
|
|
||||||
client: {
|
|
||||||
uri: '/api/client',
|
|
||||||
links: clientApiDef.links,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"version": 3,
|
|
||||||
"links": {
|
|
||||||
"feature-toggles": {
|
|
||||||
"uri": "/api/client/features"
|
|
||||||
},
|
|
||||||
"register": {
|
|
||||||
"uri": "/api/client/register"
|
|
||||||
},
|
|
||||||
"metrics": {
|
|
||||||
"uri": "/api/client/metrics"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,3 @@
|
|||||||
import { Request, Response } from 'express';
|
|
||||||
import Controller from '../controller';
|
import Controller from '../controller';
|
||||||
import FeatureController from './feature';
|
import FeatureController from './feature';
|
||||||
import MetricsController from './metrics';
|
import MetricsController from './metrics';
|
||||||
@ -6,21 +5,14 @@ import RegisterController from './register';
|
|||||||
import { IUnleashConfig } from '../../types/option';
|
import { IUnleashConfig } from '../../types/option';
|
||||||
import { IUnleashServices } from '../../types';
|
import { IUnleashServices } from '../../types';
|
||||||
|
|
||||||
const apiDef = require('./api-def.json');
|
|
||||||
|
|
||||||
export default class ClientApi extends Controller {
|
export default class ClientApi extends Controller {
|
||||||
constructor(config: IUnleashConfig, services: IUnleashServices) {
|
constructor(config: IUnleashConfig, services: IUnleashServices) {
|
||||||
super(config);
|
super(config);
|
||||||
|
|
||||||
this.get('/', this.index);
|
|
||||||
this.use('/features', new FeatureController(services, config).router);
|
this.use('/features', new FeatureController(services, config).router);
|
||||||
this.use('/metrics', new MetricsController(services, config).router);
|
this.use('/metrics', new MetricsController(services, config).router);
|
||||||
this.use('/register', new RegisterController(services, config).router);
|
this.use('/register', new RegisterController(services, config).router);
|
||||||
}
|
}
|
||||||
|
|
||||||
index(req: Request, res: Response): void {
|
|
||||||
res.json(apiDef);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ClientApi;
|
module.exports = ClientApi;
|
||||||
|
@ -1,87 +0,0 @@
|
|||||||
import supertest from 'supertest';
|
|
||||||
import { createTestConfig } from '../../test/config/test-config';
|
|
||||||
import createStores from '../../test/fixtures/store';
|
|
||||||
import getApp from '../app';
|
|
||||||
import { createServices } from '../services';
|
|
||||||
|
|
||||||
async function getSetup() {
|
|
||||||
const base = `/random${Math.round(Math.random() * 1000)}`;
|
|
||||||
const stores = createStores();
|
|
||||||
const config = createTestConfig({
|
|
||||||
server: { baseUriPath: base },
|
|
||||||
});
|
|
||||||
const services = createServices(stores, config);
|
|
||||||
const app = await getApp(config, stores, services);
|
|
||||||
|
|
||||||
return {
|
|
||||||
base,
|
|
||||||
request: supertest(app),
|
|
||||||
destroy: () => {
|
|
||||||
services.versionService.destroy();
|
|
||||||
services.clientInstanceService.destroy();
|
|
||||||
services.apiTokenService.destroy();
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let base;
|
|
||||||
let request;
|
|
||||||
let destroy;
|
|
||||||
beforeEach(async () => {
|
|
||||||
const setup = await getSetup();
|
|
||||||
base = setup.base;
|
|
||||||
request = setup.request;
|
|
||||||
destroy = setup.destroy;
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
destroy();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('api definition', () => {
|
|
||||||
expect.assertions(5);
|
|
||||||
return request
|
|
||||||
.get(`${base}/api/`)
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.expect(200)
|
|
||||||
.expect((res) => {
|
|
||||||
expect(res.body).toBeTruthy();
|
|
||||||
const { admin, client } = res.body.links;
|
|
||||||
expect(admin.uri === '/api/admin').toBe(true);
|
|
||||||
expect(client.uri === '/api/client').toBe(true);
|
|
||||||
expect(
|
|
||||||
admin.links['feature-toggles'].uri === '/api/admin/features',
|
|
||||||
).toBe(true);
|
|
||||||
expect(client.links.metrics.uri === '/api/client/metrics').toBe(
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('admin api defintion', () => {
|
|
||||||
expect.assertions(2);
|
|
||||||
return request
|
|
||||||
.get(`${base}/api/admin`)
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.expect(200)
|
|
||||||
.expect((res) => {
|
|
||||||
expect(res.body).toBeTruthy();
|
|
||||||
expect(
|
|
||||||
res.body.links['feature-toggles'].uri === '/api/admin/features',
|
|
||||||
).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('client api defintion', () => {
|
|
||||||
expect.assertions(2);
|
|
||||||
return request
|
|
||||||
.get(`${base}/api/client`)
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.expect(200)
|
|
||||||
.expect((res) => {
|
|
||||||
expect(res.body).toBeTruthy();
|
|
||||||
expect(res.body.links.metrics.uri === '/api/client/metrics').toBe(
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,16 +1,15 @@
|
|||||||
import { Request, Response } from 'express';
|
|
||||||
import { BackstageController } from './backstage';
|
import { BackstageController } from './backstage';
|
||||||
import ResetPasswordController from './auth/reset-password-controller';
|
import ResetPasswordController from './auth/reset-password-controller';
|
||||||
import { SimplePasswordProvider } from './auth/simple-password-provider';
|
import { SimplePasswordProvider } from './auth/simple-password-provider';
|
||||||
import { IUnleashConfig } from '../types/option';
|
import { IUnleashConfig } from '../types/option';
|
||||||
import { IUnleashServices } from '../types/services';
|
import { IUnleashServices } from '../types/services';
|
||||||
import { api } from './api-def';
|
|
||||||
import LogoutController from './logout';
|
import LogoutController from './logout';
|
||||||
|
|
||||||
const AdminApi = require('./admin-api');
|
const AdminApi = require('./admin-api');
|
||||||
const ClientApi = require('./client-api');
|
const ClientApi = require('./client-api');
|
||||||
const Controller = require('./controller');
|
const Controller = require('./controller');
|
||||||
import { HealthCheckController } from './health-check';
|
import { HealthCheckController } from './health-check';
|
||||||
|
|
||||||
class IndexRouter extends Controller {
|
class IndexRouter extends Controller {
|
||||||
constructor(config: IUnleashConfig, services: IUnleashServices) {
|
constructor(config: IUnleashConfig, services: IUnleashServices) {
|
||||||
super(config);
|
super(config);
|
||||||
@ -25,13 +24,8 @@ class IndexRouter extends Controller {
|
|||||||
'/auth/reset',
|
'/auth/reset',
|
||||||
new ResetPasswordController(config, services).router,
|
new ResetPasswordController(config, services).router,
|
||||||
);
|
);
|
||||||
this.get(api.uri, this.index);
|
this.use('/api/admin', new AdminApi(config, services).router);
|
||||||
this.use(api.links.admin.uri, new AdminApi(config, services).router);
|
this.use('/api/client', new ClientApi(config, services).router);
|
||||||
this.use(api.links.client.uri, new ClientApi(config, services).router);
|
|
||||||
}
|
|
||||||
|
|
||||||
async index(req: Request, res: Response): Promise<void> {
|
|
||||||
res.json(api);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user