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&addressdetails=1&q=' +
12 encodeURIComponent(q);
13
14 try {
15 const data = await fetch(nomUrl, {
16 headers: {
17 'User-Agent': 'blento.app/0.1 (contact: flobit.dev@gmail.com)',
18 Referer: env.PUBLIC_DOMAIN || 'https://blento.app'
19 }
20 });
21 console.error(data.status, data.statusText);
22 const location = await data.json();
23
24 return json(location[0]);
25 } catch (error) {
26 console.error('Error fetching location:', nomUrl, error);
27 return json({ error: 'Failed to fetch location' }, { status: 500 });
28 }
29}