unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
62 lines • 2.63 kB
JavaScript
import Controller from '../routes/controller.js';
import { ADMIN, NONE, UPDATE_CORS } from '../types/permissions.js';
import { createResponseSchema } from '../openapi/util/create-response-schema.js';
import { uiConfigSchema, } from '../openapi/spec/ui-config-schema.js';
import { emptyResponse } from '../openapi/util/standard-responses.js';
import NotFoundError from '../error/notfound-error.js';
import { createRequestSchema } from '../openapi/util/create-request-schema.js';
class UiConfigController extends Controller {
constructor(config, { openApiService, frontendApiService, uiConfigService, }) {
super(config);
this.openApiService = openApiService;
this.uiConfigService = uiConfigService;
this.frontendApiService = frontendApiService;
this.route({
method: 'get',
path: '',
handler: this.getUiConfig,
permission: NONE,
middleware: [
openApiService.validPath({
tags: ['Admin UI'],
summary: 'Get UI configuration',
description: 'Retrieves the full configuration used to set up the Unleash Admin UI.',
operationId: 'getUiConfig',
responses: {
200: createResponseSchema('uiConfigSchema'),
},
}),
],
});
this.route({
method: 'post',
path: '/cors',
handler: this.setCors,
permission: [ADMIN, UPDATE_CORS],
middleware: [
openApiService.validPath({
tags: ['Admin UI'],
summary: 'Sets allowed CORS origins',
description: 'Sets Cross-Origin Resource Sharing headers for Frontend SDK API.',
operationId: 'setCors',
requestBody: createRequestSchema('setCorsSchema'),
responses: { 204: emptyResponse },
}),
],
});
}
async getUiConfig(req, res) {
const uiConfig = await this.uiConfigService.getUiConfig(req.user);
this.openApiService.respondWithValidation(200, res, uiConfigSchema.$id, uiConfig);
}
async setCors(req, res) {
if (req.body.frontendApiOrigins) {
await this.frontendApiService.setFrontendCorsSettings(req.body.frontendApiOrigins, req.audit);
res.sendStatus(204);
return;
}
throw new NotFoundError();
}
}
export default UiConfigController;
//# sourceMappingURL=ui-config-controller.js.map