Skip to content

Commit d582e82

Browse files
fix docs search route
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 6a27ca9 commit d582e82

1 file changed

Lines changed: 7 additions & 34 deletions

File tree

apps/docs/app/api/search/route.ts

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,9 @@ import { generateSearchEmbedding } from '@/lib/embeddings'
66
export const runtime = 'nodejs'
77
export const revalidate = 0
88

9-
type SearchRequestBody = {
10-
query?: unknown
11-
q?: unknown
12-
locale?: unknown
13-
limit?: unknown
14-
}
15-
169
const DEFAULT_SEARCH_LIMIT = 10
1710
const MAX_SEARCH_LIMIT = 20
1811

19-
function getStringParam(value: unknown): string | undefined {
20-
return typeof value === 'string' ? value : undefined
21-
}
22-
2312
function getSearchLimit(value: unknown): number {
2413
const limit = Number.parseInt(String(value ?? DEFAULT_SEARCH_LIMIT), 10)
2514

@@ -30,28 +19,12 @@ function getSearchLimit(value: unknown): number {
3019
return Math.min(limit, MAX_SEARCH_LIMIT)
3120
}
3221

33-
async function getSearchParams(request: NextRequest) {
34-
const contentType = request.headers.get('content-type') ?? ''
35-
let body: SearchRequestBody = {}
36-
37-
if (contentType.includes('application/json')) {
38-
try {
39-
body = (await request.json()) as SearchRequestBody
40-
} catch {
41-
body = {}
42-
}
43-
} else if (
44-
contentType.includes('application/x-www-form-urlencoded') ||
45-
contentType.includes('multipart/form-data')
46-
) {
47-
const formData = await request.formData()
48-
body = Object.fromEntries(formData.entries())
49-
}
50-
22+
function getSearchParams(request: NextRequest) {
23+
const searchParams = request.nextUrl.searchParams
5124
return {
52-
query: getStringParam(body.query) || getStringParam(body.q) || '',
53-
locale: getStringParam(body.locale) || 'en',
54-
limit: getSearchLimit(body.limit),
25+
query: searchParams.get('query') || searchParams.get('q') || '',
26+
locale: searchParams.get('locale') || 'en',
27+
limit: getSearchLimit(searchParams.get('limit')),
5528
}
5629
}
5730

@@ -60,9 +33,9 @@ async function getSearchParams(request: NextRequest) {
6033
* - English: Vector embeddings + keyword search
6134
* - Other languages: Keyword search only
6235
*/
63-
export async function POST(request: NextRequest) {
36+
export async function GET(request: NextRequest) {
6437
try {
65-
const { query, locale, limit } = await getSearchParams(request)
38+
const { query, locale, limit } = getSearchParams(request)
6639

6740
if (!query || query.trim().length === 0) {
6841
return NextResponse.json([])

0 commit comments

Comments
 (0)