fix: make server logic run on the server
All checks were successful
deploy to cloudflare pages / deploy (push) Successful in 31s
All checks were successful
deploy to cloudflare pages / deploy (push) Successful in 31s
but correctly and more cool
This commit is contained in:
parent
dc55bf3a7a
commit
8ae9355ec9
2 changed files with 4 additions and 19 deletions
|
@ -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 };
|
||||
};
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue