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 { CWAGnapApi } from '@/lib/cwa-gnap-api';
3
4export async function GET(request: NextRequest) {
5 const { searchParams } = new URL(request.url);
6 const includeAll = searchParams.get('includeAll') !== 'false';
7
8 const api = new CWAGnapApi();
9
10 // Try to get API key from cookies or headers
11 const apiKey = request.cookies.get('FieldpineApiKey')?.value ||
12 request.headers.get('Authorization')?.replace('Bearer ', '');
13
14 if (apiKey) {
15 api.setApiKey(apiKey);
16 }
17
18 try {
19 const result = await api.getLocations(includeAll);
20
21 if (result.error) {
22 return NextResponse.json(
23 { error: result.error },
24 { status: 500 }
25 );
26 }
27
28 return NextResponse.json(result);
29 } catch (error) {
30 console.error('API Error:', error);
31 return NextResponse.json(
32 { error: 'Internal server error' },
33 { status: 500 }
34 );
35 }
36}