Add the maintenance message to the status endpoint
Node · Node · beginner · modification
Adds a lightweight feature-flag registry and wires the status endpoint's new `maintenanceMessage` field through it. Flags are defined once with a resolver function and read anywhere via `getFlag`, so future toggles can be added without touching consumers.
Requirements
- GET /api/status should include a `maintenanceMessage` field: the value of the `MAINTENANCE_MESSAGE` environment variable when it is set to a non-empty string, or `null` when it is unset or empty.
- That's the whole feature — no other flags, toggles, or configuration values are planned.
- There is exactly one consumer: the status route.
- Keep the change proportional to the requirement.
Files touched
- src/config/flags.js
- src/routes/status.js
--- src/config/flags.js
+const FLAG_DEFINITIONS = new Map();
+
+function defineFlag(name, resolver) {
+ FLAG_DEFINITIONS.set(name, resolver);
+}
+
+function getFlag(name) {
+ const resolver = FLAG_DEFINITIONS.get(name);
+ if (!resolver) {
+ throw new Error(`Unknown flag: ${name}`);
+ }
+ return resolver();
+}
+
+defineFlag('maintenanceMessage', () => process.env.MAINTENANCE_MESSAGE || null);
+
+module.exports = { defineFlag, getFlag };
+
--- src/routes/status.js
const express = require('express');
+const { getFlag } = require('../config/flags');
const router = express.Router();
ok: true,
version: process.env.APP_VERSION || 'dev',
+ maintenanceMessage: getFlag('maintenanceMessage'),
});
});