health.js 671 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. // 健康检查与默认根目录
  3. const fs = require('fs');
  4. const { sendJson } = require('../util.js');
  5. function register(app, ctx) {
  6. app.get('/api/default-root', async ({ res }) => {
  7. sendJson(res, 200, { root: ctx.workspace.getWorkspaceRoot() });
  8. });
  9. app.get('/healthz', async ({ res }) => {
  10. sendJson(res, 200, { ok: true, workspace: ctx.workspace.getWorkspaceRoot() });
  11. });
  12. app.get('/readyz', async ({ res }) => {
  13. sendJson(res, 200, {
  14. ok: !!ctx.config.apiKey,
  15. workspaceReady: fs.existsSync(ctx.workspace.getWorkspaceRoot()),
  16. crawlReady: !!ctx.session.getKsid(),
  17. });
  18. });
  19. }
  20. module.exports = { register };