your personal website on atproto - mirror
blento.app
1import { env } from '$env/dynamic/private';
2import { json } from '@sveltejs/kit';
3
4export async function GET({ url }) {
5 const q = url.searchParams.get('q');
6 if (!q) {
7 return json({ error: 'No search provided' }, { status: 400 });
8 }
9
10 const nomUrl =
11 'https://nominatim.openstreetmap.org/search?format=json&q=' + encodeURIComponent(q);
12
13 try {
14 const data = await fetch(nomUrl, {
15 headers: {
16 'User-Agent': 'blento.app/0.1 (contact: flobit.dev@gmail.com)',
17 Referer: env.PUBLIC_DOMAIN || 'https://blento.app'
18 }
19 });
20 console.error(data.status, data.statusText);
21 const location = await data.json();
22
23 return json(location[0]);
24 } catch (error) {
25 console.error('Error fetching location:', nomUrl, error);
26 return json({ error: 'Failed to fetch location' }, { status: 500 });
27 }
28}