UNPKG

unleash-server

Version:

Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.

58 lines 2.7 kB
import { ADMIN, UPDATE_MAINTENANCE_MODE, } from '../../types/index.js'; import Controller from '../../routes/controller.js'; import { createRequestSchema, createResponseSchema, emptyResponse, getStandardResponses, } from '../../openapi/index.js'; import { maintenanceSchema, } from '../../openapi/spec/maintenance-schema.js'; export default class MaintenanceController extends Controller { constructor(config, { maintenanceService, openApiService, }) { super(config); this.maintenanceService = maintenanceService; this.openApiService = openApiService; this.logger = config.getLogger('routes/admin-api/maintenance'); this.route({ method: 'post', path: '', permission: [ADMIN, UPDATE_MAINTENANCE_MODE], handler: this.toggleMaintenance, middleware: [ this.openApiService.validPath({ summary: 'Enabled/disabled maintenance mode', description: 'Lets administrators put Unleash into a mostly read-only mode. While Unleash is in maintenance mode, users can not change any configuration settings', tags: ['Maintenance'], operationId: 'toggleMaintenance', responses: { 204: emptyResponse, ...getStandardResponses(400, 401, 403), }, requestBody: createRequestSchema('toggleMaintenanceSchema'), }), ], }); this.route({ method: 'get', path: '', permission: [ADMIN, UPDATE_MAINTENANCE_MODE], handler: this.getMaintenance, middleware: [ this.openApiService.validPath({ summary: 'Get maintenance mode status', description: 'Tells you whether maintenance mode is enabled or disabled', tags: ['Maintenance'], operationId: 'getMaintenance', responses: { 200: createResponseSchema('maintenanceSchema'), ...getStandardResponses(401, 403), }, }), ], }); } async toggleMaintenance(req, res) { await this.maintenanceService.toggleMaintenanceMode(req.body, req.audit); res.status(204).end(); } async getMaintenance(_req, res) { const settings = await this.maintenanceService.getMaintenanceSetting(); this.openApiService.respondWithValidation(200, res, maintenanceSchema.$id, settings); } } //# sourceMappingURL=maintenance-controller.js.map