Compare commits
4 commits
3c7bca466a
...
5d56b382ce
Author | SHA1 | Date | |
---|---|---|---|
5d56b382ce | |||
dba6eced88 | |||
cc11368926 | |||
536b84af2d |
7 changed files with 15 additions and 21 deletions
|
@ -1,4 +1,5 @@
|
||||||
export async function handleError({ error, event, status, message }) {
|
export async function handleError({ error, event, status, message }) {
|
||||||
|
console.error(error)
|
||||||
return {
|
return {
|
||||||
message
|
message
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,6 +4,7 @@ export async function handle({ event, resolve }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleError({ error, event, status, message }) {
|
export async function handleError({ error, event, status, message }) {
|
||||||
|
console.error(error)
|
||||||
return {
|
return {
|
||||||
message
|
message
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const API_URL = "https://ale-dev.teck-developer.com/api";
|
const API_URL = "https://ale-dev.teck-developer.com/api";
|
||||||
|
|
||||||
const getAllRoutes = async () => {
|
const getAllRoutes = async (fetch) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
|
||||||
const response = await fetch(`${API_URL}/all-routes`);
|
const response = await fetch(`${API_URL}/all-routes`);
|
||||||
|
@ -10,7 +10,7 @@ const getAllRoutes = async () => {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getRouteCategories = async () => {
|
const getRouteCategories = async (fetch) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
|
||||||
const response = await fetch(`${API_URL}/route-categories`);
|
const response = await fetch(`${API_URL}/route-categories`);
|
||||||
|
@ -20,7 +20,7 @@ const getRouteCategories = async () => {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getRouteByCategory = async (categoryId: number) => {
|
const getRouteByCategory = async (fetch,categoryId: number) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
const response = await fetch(`${API_URL}/route-by-category/${categoryId}`);
|
const response = await fetch(`${API_URL}/route-by-category/${categoryId}`);
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
|
@ -29,7 +29,7 @@ const getRouteByCategory = async (categoryId: number) => {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getRoute = async (routeId: number) => {
|
const getRoute = async (fetch,routeId: number) => {
|
||||||
let data = {};
|
let data = {};
|
||||||
const response = await fetch(`${API_URL}/route/${routeId}`);
|
const response = await fetch(`${API_URL}/route/${routeId}`);
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
|
@ -39,7 +39,7 @@ const getRoute = async (routeId: number) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const getSport = async (routeId: number, sportId: number) => {
|
const getSport = async (fetch,routeId: number, sportId: number) => {
|
||||||
let data = {};
|
let data = {};
|
||||||
const response = await fetch(`${API_URL}/route/${routeId}/${sportId}`);
|
const response = await fetch(`${API_URL}/route/${routeId}/${sportId}`);
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
|
@ -48,7 +48,7 @@ const getSport = async (routeId: number, sportId: number) => {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPlacemarks = async (routeId: number, sportId: number) => {
|
const getPlacemarks = async (fetch,routeId: number, sportId: number) => {
|
||||||
let data = {};
|
let data = {};
|
||||||
const response = await fetch(`${API_URL}/getPlacemarks/${routeId}/${sportId}`);
|
const response = await fetch(`${API_URL}/getPlacemarks/${routeId}/${sportId}`);
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
|
|
|
@ -1,11 +1,3 @@
|
||||||
export const prerender = false;
|
export const prerender = false;
|
||||||
export const ssr = true;
|
export const ssr = true;
|
||||||
export const csr = true;
|
export const csr = true;
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a global configuration for using sveltekit
|
|
||||||
* custom 'fetch' function that enables a lot of things
|
|
||||||
*/
|
|
||||||
export async function load({ fetch }) {
|
|
||||||
window.fetch = fetch;
|
|
||||||
}
|
|
|
@ -2,10 +2,10 @@
|
||||||
import { getRouteCategories } from '$lib/repo.js';
|
import { getRouteCategories } from '$lib/repo.js';
|
||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
|
|
||||||
export async function load() {
|
export async function load({fetch}) {
|
||||||
let categories = [];
|
let categories = [];
|
||||||
try {
|
try {
|
||||||
categories = await getRouteCategories();
|
categories = await getRouteCategories(fetch);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
error(500);
|
error(500);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { getRouteByCategory, getRouteCategories } from '$lib/repo.js';
|
import { getRouteByCategory, getRouteCategories } from '$lib/repo.js';
|
||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
|
|
||||||
export async function load({ params }) {
|
export async function load({ fetch, params }) {
|
||||||
const categories: App.Category[] = await getRouteCategories();
|
const categories: App.Category[] = await getRouteCategories(fetch);
|
||||||
const categoryId = Number(params.slug);
|
const categoryId = Number(params.slug);
|
||||||
|
|
||||||
const category: App.Category = categories.find(c => c.id === categoryId) as App.Category;
|
const category: App.Category = categories.find(c => c.id === categoryId) as App.Category;
|
||||||
|
@ -13,7 +13,7 @@ export async function load({ params }) {
|
||||||
|
|
||||||
const toReturn = {
|
const toReturn = {
|
||||||
category: category.name_it,
|
category: category.name_it,
|
||||||
routes: await getRouteByCategory(categoryId),
|
routes: await getRouteByCategory(fetch, categoryId),
|
||||||
}
|
}
|
||||||
|
|
||||||
return toReturn;
|
return toReturn;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { getRoute } from '$lib/repo.js';
|
import { getRoute } from '$lib/repo.js';
|
||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
|
|
||||||
export async function load({ params }) {
|
export async function load({ fetch, params }) {
|
||||||
const routeId = Number(params.slug);
|
const routeId = Number(params.slug);
|
||||||
const route = await getRoute(routeId);
|
const route = await getRoute(fetch, routeId);
|
||||||
|
|
||||||
if (!route) {
|
if (!route) {
|
||||||
error(404);
|
error(404);
|
||||||
|
|
Loading…
Reference in a new issue