Checking whether the service is up required an account, so the answer lived where the people asking could not reach it. The page is rendered on the server with no script at all and refreshes through a meta tag: a status page that needs a working browser is useless at the moment it is read. Two rules follow from it being public. A repository the forge does not list as public keeps its environment visible but loses its name, and the banner always states the worst true thing — a failed deployment forbids the green headline even while the bot answers. WEB_PUBLIC_STATUS=false removes page and route together. /api/status gives the same in JSON, which is what a monitor should watch rather than /api/health — the latter only says the process is alive. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
73 lines
2.7 KiB
JavaScript
73 lines
2.7 KiB
JavaScript
import { ACCESS_LEVELS } from '../../config/constants.js';
|
|
import { registerAuthRoutes } from '../auth/routes.js';
|
|
import { openEventStream } from '../events.js';
|
|
import { VERSION, buildAt } from '../services/build-info.js';
|
|
import { registerCommunityRoutes } from './community.js';
|
|
import { registerConfigurationRoutes } from './configuration.js';
|
|
import { registerDeploymentRoutes } from './deployments.js';
|
|
import { registerDiscordRoutes } from './discord.js';
|
|
import { registerLogRoutes } from './logs.js';
|
|
import { registerOrganizationRoutes } from './organization.js';
|
|
import { registerOverviewRoutes } from './overview.js';
|
|
import { registerProjectRoutes } from './projects.js';
|
|
import { registerReleaseRoutes } from './releases.js';
|
|
import { registerRepositoryRoutes } from './repositories.js';
|
|
import { registerSearchRoutes } from './search.js';
|
|
import { registerSettingsRoutes } from './settings.js';
|
|
import { registerStatusRoutes } from './status.js';
|
|
import { registerWikiRoutes } from './wiki.js';
|
|
|
|
/**
|
|
* Route registration order matters only for readability: the router matches on
|
|
* the full pattern, not on declaration order.
|
|
*/
|
|
export function registerApiRoutes(router, { setupOnly = false } = {}) {
|
|
// Liveness probe for a reverse proxy or an uptime monitor. Registered first so
|
|
// it answers even in bootstrap mode, when nothing else is mounted.
|
|
router.get(
|
|
'/api/health',
|
|
({ context }) => ({
|
|
status: context.client?.isReady?.() ? 'ok' : 'starting',
|
|
setupOnly: context.setupOnly,
|
|
uptimeMs: Date.now() - context.startedAt,
|
|
version: VERSION,
|
|
buildAt: buildAt(),
|
|
}),
|
|
{ public: true },
|
|
);
|
|
|
|
registerAuthRoutes(router);
|
|
registerConfigurationRoutes(router);
|
|
// The public documentation stays reachable even while the bot is being set up.
|
|
registerWikiRoutes(router);
|
|
// So does the status page: a bot still being configured is exactly what an
|
|
// uptime monitor, or a visitor, would want to be told.
|
|
registerStatusRoutes(router);
|
|
|
|
// Long-lived stream the pages listen to instead of polling (M16-T12).
|
|
router.get(
|
|
'/api/events',
|
|
({ request, response, actor }) => {
|
|
openEventStream(request, response, actor);
|
|
},
|
|
{ access: ACCESS_LEVELS.STAFF },
|
|
);
|
|
|
|
// In bootstrap mode the bot is not connected and the database may be empty:
|
|
// only the wizard makes sense.
|
|
if (setupOnly) return router;
|
|
|
|
registerOverviewRoutes(router);
|
|
registerOrganizationRoutes(router);
|
|
registerProjectRoutes(router);
|
|
registerRepositoryRoutes(router);
|
|
registerReleaseRoutes(router);
|
|
registerDeploymentRoutes(router);
|
|
registerDiscordRoutes(router);
|
|
registerCommunityRoutes(router);
|
|
registerSearchRoutes(router);
|
|
registerSettingsRoutes(router);
|
|
registerLogRoutes(router);
|
|
return router;
|
|
}
|