1
0
Fork 0

Use of Server Components for easier Data fetching + start use of v2 API

This commit is contained in:
Neshura 2023-06-10 16:14:53 +02:00
parent 49ceda5575
commit f23c9dc0f1
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
6 changed files with 195 additions and 5 deletions
components/server

View file

@ -0,0 +1,27 @@
import { Game } from "@/types/stellaris"
type Parameter = {
key: string,
val: string | number
}
const baseUrl = 'http://stellaris.neshweb.net/api/v2'
export const generateUrl = (url: string, params?: Parameter[]) => {
let query: string = baseUrl + url;
if (params && params.length > 0) {
query = query + '?';
params.forEach((param, idx) => {
query = query + param.key + '=' + param.val;
if (idx + 1 != params.length) {
query = query + '&';
}
});
}
return query;
}
export const fetchGameGroups = async (game: Game) => {
const gameGroups = await fetch(generateUrl('/game_groups', [{key: "game_id", val: game.id}])).then((res) => res.json())
return gameGroups
}