EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
route.ts
Go to the documentation of this file.
1import { NextRequest, NextResponse } from 'next/server';
2import { cwaPosApi } from '@/lib/cwa-pos-api';
3
4export async function GET(request: NextRequest) {
5 const { searchParams } = new URL(request.url);
6 const searchTerm = searchParams.get('q') || searchParams.get('search') || '';
7 const limit = parseInt(searchParams.get('limit') || '30');
8
9 // Try to get API key from cookies or headers
10 const apiKey = request.cookies.get('FieldpineApiKey')?.value ||
11 request.headers.get('Authorization')?.replace('Bearer ', '');
12
13 if (apiKey) {
14 cwaPosApi.setApiKey(apiKey);
15 }
16
17 try {
18 const result = await cwaPosApi.searchProducts(searchTerm, limit);
19
20 if (result.error) {
21 return NextResponse.json(
22 { error: result.error },
23 { status: 500 }
24 );
25 }
26
27 return NextResponse.json(result);
28 } catch (error) {
29 console.error('POS API Error:', error);
30 return NextResponse.json(
31 { error: 'Internal server error' },
32 { status: 500 }
33 );
34 }
35}