You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
672 B

11 months ago
  1. const { SystemSettings } = require("../../models/systemSettings");
  2. // Explicitly check that a specific feature flag is enabled.
  3. // This should match the key in the SystemSetting label.
  4. function featureFlagEnabled(featureFlagKey = null) {
  5. return async (_, response, next) => {
  6. if (!featureFlagKey) return response.sendStatus(401).end();
  7. const flagValue = (
  8. await SystemSettings.get({ label: String(featureFlagKey) })
  9. )?.value;
  10. if (!flagValue) return response.sendStatus(401).end();
  11. if (flagValue === "enabled") {
  12. next();
  13. return;
  14. }
  15. return response.sendStatus(401).end();
  16. };
  17. }
  18. module.exports = {
  19. featureFlagEnabled,
  20. };