Files
Hermes fca56ab77e T1/Phase 1: scaffold Vite SPA + Hono API + Bun worker
- apps/web: Vite + React 19 + TanStack Router/Query + shadcn/ui
   - apps/api: Hono + Bun on :3001 with /api/health, /api/auth/*, /mcp stubs
   - apps/worker: Bun worker stub, DB connection, graceful SIGTERM
   - apps/web-legacy/: old Next.js code moved aside (preserved for T2-T8 reference)
   - Dockerfiles: api (Bun), worker (Bun), spa (multi-stage Caddy)
   - Caddyfile: serves dist + reverse-proxies /api/* + /mcp to api
   - docker-compose.yml: 4-service target (api, spa, db, worker)
   - packages/db/src/client.ts: shared Drizzle client for api + worker
   - db/client.ts: root-level alias for convenience

   Parent: t_e1cbd87d -> t_24c9c3fd (T0)
2026-08-01 01:15:31 +00:00

47 lines
1.6 KiB
TypeScript

// AGENT INSTRUCTION: After every write (INSERT/UPDATE/DELETE), you MUST:
// 1. Insert activity feed entry
// 2. Call pg.notify('project_e_events', JSON.stringify({ type, action, id, workspace_id }))
// See AGENTS.md for full rules.
import { NextRequest, NextResponse } from 'next/server';
import { withAuth, createErrorResponse, resolveActiveDomain } from '@/lib/auth';
import { searchEntities } from '@/lib/search-service';
// GET /api/search?q=&type=&domain=&limit=&offset=
// Full-text search across all entity types using PostgreSQL tsvector/tsquery
export const GET = withAuth(async (request: NextRequest, user) => {
const { searchParams } = new URL(request.url);
const q = (searchParams.get('q') || '').trim();
const types = searchParams.get('types')?.split(',').filter(Boolean) || ['task', 'note', 'project', 'habit', 'domain'];
let domain = searchParams.get('domain') || undefined;
if (!domain) {
const active = await resolveActiveDomain(user);
domain = active.id;
}
const limit = Math.max(1, Math.min(50, parseInt(searchParams.get('limit') || '20')));
const offset = Math.max(0, parseInt(searchParams.get('offset') || '0'));
if (!q) {
return NextResponse.json({ results: [], totalCount: 0 });
}
try {
const { results, totalCount } = await searchEntities({
query: q,
types,
domainId: domain,
limit,
offset,
});
return NextResponse.json({
results,
totalCount,
query: q,
});
} catch (error) {
console.error('[search GET] error:', error);
return createErrorResponse('INTERNAL_ERROR', 'Search failed', 500);
}
});