chore: Add GeoJSON endpoint to retrieve combined GeoJSON data from static files
This commit is contained in:
@@ -5,12 +5,6 @@ import type { Adventure, VisitedRegion } from '$lib/types';
|
||||
const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
|
||||
|
||||
export const load = (async (event) => {
|
||||
let countryCodesToFetch = ['FR', 'US', 'CA', 'DE', 'AU', 'MX', 'JP'];
|
||||
let geoJSON = {
|
||||
type: 'FeatureCollection',
|
||||
features: []
|
||||
};
|
||||
|
||||
if (!event.locals.user) {
|
||||
return redirect(302, '/login');
|
||||
} else {
|
||||
@@ -20,6 +14,8 @@ export const load = (async (event) => {
|
||||
}
|
||||
});
|
||||
|
||||
let geoJsonUrl = `${endpoint}/api/geojson/` as string;
|
||||
|
||||
let visitedRegionsFetch = await fetch(`${endpoint}/api/visitedregion/`, {
|
||||
headers: {
|
||||
Cookie: `${event.cookies.get('auth')}`
|
||||
@@ -27,19 +23,6 @@ export const load = (async (event) => {
|
||||
});
|
||||
let visitedRegions = (await visitedRegionsFetch.json()) as VisitedRegion[];
|
||||
|
||||
await Promise.all(
|
||||
countryCodesToFetch.map(async (code) => {
|
||||
let res = await fetch(`${endpoint}/static/data/${code.toLowerCase()}.json`);
|
||||
console.log('fetching ' + code);
|
||||
let json = await res.json();
|
||||
if (!json) {
|
||||
console.error(`Failed to fetch ${code} GeoJSON`);
|
||||
} else {
|
||||
geoJSON.features = geoJSON.features.concat(json.features);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
if (!visitedFetch.ok) {
|
||||
console.error('Failed to fetch visited adventures');
|
||||
return redirect(302, '/login');
|
||||
@@ -61,7 +44,7 @@ export const load = (async (event) => {
|
||||
return {
|
||||
props: {
|
||||
markers,
|
||||
geoJSON,
|
||||
geoJsonUrl,
|
||||
visitedRegions
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user