ggsh.service.js 746 B

123456789101112131415161718192021222324252627282930
  1. import { API_BASE } from "../config";
  2. export const getStatus = async () => {
  3. try {
  4. const res = await fetch(API_BASE + "/");
  5. if (!res.ok) {
  6. throw Error(res.statusText);
  7. }
  8. return await res.json();
  9. } catch (err) {
  10. return {status: err.message, version: null}
  11. }
  12. }
  13. export const createGame = async (name, timer) => {
  14. const res = await fetch(API_BASE + "/game", {
  15. method: "PUT",
  16. headers: {
  17. "Authorization": `Name ${name}`,
  18. "Content-Type": "application/json",
  19. },
  20. body: JSON.stringify({ timer }),
  21. });
  22. if (!res.ok) {
  23. throw Error(res.statusText);
  24. }
  25. const { gameId } = await res.json();
  26. return gameId;
  27. }