123456789101112131415161718192021222324252627282930 |
- import { API_BASE } from "../config";
- export const getStatus = async () => {
- try {
- const res = await fetch(API_BASE + "/");
- if (!res.ok) {
- throw Error(res.statusText);
- }
- return await res.json();
- } catch (err) {
- return {status: err.message, version: null}
- }
- }
- export const createGame = async (name, timer) => {
- const res = await fetch(API_BASE + "/game", {
- method: "PUT",
- headers: {
- "Authorization": `Name ${name}`,
- "Content-Type": "application/json",
- },
- body: JSON.stringify({ timer }),
- });
- if (!res.ok) {
- throw Error(res.statusText);
- }
- const { gameId } = await res.json();
- return gameId;
- }
|