diff --git a/src/routes/api/data/+server.ts b/src/routes/game/+page.server.ts similarity index 89% rename from src/routes/api/data/+server.ts rename to src/routes/game/+page.server.ts index e16f72c..feb5753 100644 --- a/src/routes/api/data/+server.ts +++ b/src/routes/game/+page.server.ts @@ -1,8 +1,8 @@ -import type { RequestHandler } from "./$types"; +import type { PageServerLoad } from "./$types"; import { createGame, getMetro, getStops, getTram, type GameData, type GameOptions } from "$lib"; import { error } from "@sveltejs/kit"; -export const GET: RequestHandler = async ({ fetch, url }) => { +export const load: PageServerLoad = async ({ fetch, url }) => { const stops = await getStops(fetch); const mode = url.searchParams.get("mode"); @@ -41,12 +41,12 @@ export const GET: RequestHandler = async ({ fetch, url }) => { } const gameId = createGame(randomStop); - const data: GameData = { + const gameData: GameData = { lines: options.mode === "easy" || options.mode === "hard" ? lineColors : [], stops: options.mode === "easy" ? crossingStops : [], stopName: randomStop.properties!.nom, gameId, }; - return Response.json(data); + return { gameData }; }; diff --git a/src/routes/game/+page.ts b/src/routes/game/+page.ts index 66c3b63..a3d1578 100644 --- a/src/routes/game/+page.ts +++ b/src/routes/game/+page.ts @@ -1,16 +1 @@ -import type { PageLoad } from "./$types"; -import type { GameData } from "$lib"; -import { error } from "@sveltejs/kit"; - -export const load: PageLoad = async ({ fetch, url }) => { - const res = await fetch("/api/data?" + url.searchParams); - - if (!res.ok) { - return error(400, await res.text()); - } else { - const gameData: GameData = await res.json(); - return { gameData }; - } -}; - export const ssr = false;