sourcebot/packages/web/src/app/api/(server)/search/route.ts
Michael Sukkarieh 553f5d25f7
Add tenant ID concept into web app and backend (#160)
* hacked together a example of using zoekt grpc api

* provide tenant id to zoekt git indexer

* update zoekt version to point to multitenant branch

* pipe tenant id through header to zoekt

* remove incorrect submodule reference and settings typo

* update zoekt commit

* remove unused yarn script

* remove unused grpc client in web server

* remove unneeded deps and improve tenant id log

* pass tenant id when creating repo in db

* add mt yarn script

* add nocheckin comment to tenant id in v2 schema

---------

Co-authored-by: bkellam <bshizzle1234@gmail.com>
2025-01-14 16:46:36 -08:00

32 lines
No EOL
971 B
TypeScript

'use server';
import { search } from "@/lib/server/searchService";
import { searchRequestSchema } from "@/lib/schemas";
import { schemaValidationError, serviceErrorResponse } from "@/lib/serviceError";
import { isServiceError } from "@/lib/utils";
import { NextRequest } from "next/server";
export const POST = async (request: NextRequest) => {
const body = await request.json();
const tenantId = await request.headers.get("X-Tenant-ID");
console.log(`Search request received. Tenant ID: ${tenantId}`);
const parsed = await searchRequestSchema.safeParseAsync({
...body,
...(tenantId && { tenantId: parseInt(tenantId) }),
});
if (!parsed.success) {
return serviceErrorResponse(
schemaValidationError(parsed.error)
);
}
const response = await search(parsed.data);
if (isServiceError(response)) {
return serviceErrorResponse(response);
}
return Response.json(response);
}