change saerroFetch to GET to allow caching

This commit is contained in:
41666 2023-05-21 13:40:51 -04:00
parent 49fffc20a3
commit 2712285a35
2 changed files with 16 additions and 13 deletions

View file

@ -1,4 +1,4 @@
import type { LoaderArgs } from "@remix-run/cloudflare"; import type { LoaderArgs, V2_MetaFunction } from "@remix-run/cloudflare";
import { json } from "@remix-run/cloudflare"; import { json } from "@remix-run/cloudflare";
import { useLoaderData } from "@remix-run/react"; import { useLoaderData } from "@remix-run/react";
import { import {
@ -14,7 +14,11 @@ export const loader = async ({ params }: LoaderArgs) => {
return json(await worldQuery(params.id as string)); return json(await worldQuery(params.id as string));
}; };
export default function Index() { export const meta: V2_MetaFunction<typeof loader> = ({ data }) => {
return [{ title: `${data.world.name} | PS2.LIVE` }];
};
export default function World() {
const { world } = useLoaderData<WorldResponse>(); const { world } = useLoaderData<WorldResponse>();
return ( return (

View file

@ -1,11 +1,12 @@
export const saerroFetch = async <T>(query: string): Promise<T> => { export const saerroFetch = async <T>(query: string): Promise<T> => {
const response = await fetch("https://saerro.ps2.live/graphql", { const response = await fetch(
method: "POST", `https://saerro.ps2.live/graphql?query=${query}`,
headers: { {
"Content-Type": "application/json", cf: {
cacheTtl: 60,
}, },
body: JSON.stringify({ query }), }
}); );
const json: { data: T } = await response.json(); const json: { data: T } = await response.json();
return json.data; return json.data;
}; };
@ -52,7 +53,7 @@ export type IndexResponse = {
}; };
export const indexQuery = async (): Promise<IndexResponse> => { export const indexQuery = async (): Promise<IndexResponse> => {
const query = `query { const query = `{
health { health {
ingestReachable ingestReachable
ingest ingest
@ -128,7 +129,7 @@ export const allClasses = [
]; ];
export const worldQuery = async (worldID: string): Promise<WorldResponse> => { export const worldQuery = async (worldID: string): Promise<WorldResponse> => {
const query = `query { const query = `{
world(by: {id: ${Number(worldID)}}) { world(by: {id: ${Number(worldID)}}) {
id id
name name
@ -162,8 +163,6 @@ export const worldQuery = async (worldID: string): Promise<WorldResponse> => {
} }
}`; }`;
console.log(query);
const worldData: WorldResponse = await saerroFetch(query); const worldData: WorldResponse = await saerroFetch(query);
return worldData; return worldData;