fix: make server logic run on the server
All checks were successful
deploy to cloudflare pages / deploy (push) Successful in 31s

but correctly and more cool
This commit is contained in:
uku 2024-10-26 00:26:57 +02:00
parent dc55bf3a7a
commit 8ae9355ec9
Signed by: uku
SSH key fingerprint: SHA256:4P0aN6M8ajKukNi6aPOaX0LacanGYtlfjmN+m/sHY/o
2 changed files with 4 additions and 19 deletions

View file

@ -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 };
};

View file

@ -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;