+page.server.js 539 B

12345678910111213141516171819202122
  1. import {PUBLIC_API_URL} from "$env/static/public";
  2. import {error} from "@sveltejs/kit";
  3. export async function load({fetch, request}){
  4. const res = await fetch(`${PUBLIC_API_URL}/game`, {
  5. method: "GET",
  6. headers: {
  7. "Content-Type": "application/json",
  8. Cookie: request.headers.get("cookie") ?? ""
  9. }
  10. });
  11. const data = await res.json();
  12. if(!res.ok){
  13. error(res.status, {
  14. message: data.error.message,
  15. back: "/"
  16. });
  17. }
  18. return {data};
  19. }