File size: 1,497 Bytes
a5d1c1b
 
 
 
 
 
 
 
 
 
 
 
 
 
61b1da1
a5d1c1b
 
 
 
 
 
 
 
 
 
 
 
 
61b1da1
a5d1c1b
61b1da1
a5d1c1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61b1da1
a5d1c1b
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { healthRouter } from './routes/health.js';
import { reposRouter } from './routes/repos.js';

export const app = new Hono();

// Enable CORS for all incoming agent/developer requests
app.use(
  '*',
  cors({
    origin: '*',
    allowMethods: ['GET', 'HEAD', 'OPTIONS'],
    allowHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'],
    exposeHeaders: ['X-Ever-Brain-Path', 'X-Ever-Brain-Branch'],
  })
);

// Route mounts
app.route('/health', healthRouter);
app.route('/repos', reposRouter);

// Backward compatibility mount: /projects/:owner/:repo -> /repos/:owner/:repo
app.route('/projects', reposRouter);

// Root route
app.get('/', (c) => {
  return c.json({
    name: 'Ever-Brain API',
    version: '1.0.0',
    description: 'Ever-Brain Stateless Content Access Layer',
    endpoints: [
      'GET /health',
      'GET /repos/:owner/:repo',
      'GET /repos/:owner/:repo/files',
      'GET /repos/:owner/:repo/file/*path',
      'GET /repos/:owner/:repo/search?q=:query',
    ],
  });
});

// 404 Handler
app.notFound((c) => {
  return c.json(
    {
      error: `Route not found: ${c.req.method} ${c.req.path}`,
      code: 'NOT_FOUND',
    },
    404
  );
});

// Global Error Handler
app.onError((err, c) => {
  console.error('[Ever-Brain API Unhandled Error]', err);
  return c.json(
    {
      error: err.message || 'Internal server error',
      code: 'INTERNAL_SERVER_ERROR',
    },
    500
  );
});