This commit is contained in:
+24
-47
@@ -2,7 +2,7 @@ import type { Game, User } from "./interfaces";
|
||||
|
||||
export function subscribe(endpoint: string) {
|
||||
const config = useRuntimeConfig();
|
||||
const evtSource = new EventSource(new URL(endpoint, config.public.endpoint), {
|
||||
const evtSource = new EventSource(config.public.endpoint + endpoint, {
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
@@ -11,12 +11,9 @@ export function subscribe(endpoint: string) {
|
||||
|
||||
export async function getLobby() {
|
||||
const config = useRuntimeConfig();
|
||||
const req = await useFetch<Array<Game>>(
|
||||
new URL("/games", config.public.endpoint).href,
|
||||
{
|
||||
credentials: "include",
|
||||
}
|
||||
);
|
||||
const req = await useFetch<Array<Game>>(config.public.endpoint + "/games", {
|
||||
credentials: "include",
|
||||
});
|
||||
if (req.data.value == null) {
|
||||
throw new Error("Lobby answer is empty");
|
||||
}
|
||||
@@ -26,7 +23,7 @@ export async function getLobby() {
|
||||
export async function whoami() {
|
||||
const config = useRuntimeConfig();
|
||||
const { data, pending, error, refresh } = await useFetch<User>(
|
||||
new URL("/whoami", config.public.endpoint).href,
|
||||
config.public.endpoint + "/whoami",
|
||||
{
|
||||
credentials: "include",
|
||||
}
|
||||
@@ -48,13 +45,10 @@ export async function whoami() {
|
||||
|
||||
export async function createGame() {
|
||||
const config = useRuntimeConfig();
|
||||
const res = await $fetch<Game>(
|
||||
new URL("/games", config.public.endpoint).href,
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
}
|
||||
);
|
||||
const res = await $fetch<Game>(config.public.endpoint + "/games", {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
});
|
||||
console.log(res);
|
||||
navigateTo("/game/" + res._id);
|
||||
}
|
||||
@@ -62,7 +56,7 @@ export async function createGame() {
|
||||
export async function startGame(game: string) {
|
||||
const config = useRuntimeConfig();
|
||||
const res = await $fetch<Game>(
|
||||
new URL(`games/${game}/start`, config.public.endpoint).href,
|
||||
config.public.endpoint + `games/${game}/start`,
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
@@ -73,7 +67,7 @@ export async function startGame(game: string) {
|
||||
export async function joinGame(game: string) {
|
||||
const config = useRuntimeConfig();
|
||||
const res = await $fetch<Game>(
|
||||
new URL(`games/${game}/join`, config.public.endpoint).href,
|
||||
config.public.endpoint + `games/${game}/join`,
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
@@ -83,7 +77,7 @@ export async function joinGame(game: string) {
|
||||
|
||||
export async function endTurn(game: string) {
|
||||
const config = useRuntimeConfig();
|
||||
await $fetch(new URL(`games/${game}/endTurn`, config.public.endpoint).href, {
|
||||
await $fetch(config.public.endpoint + `games/${game}/endTurn`, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
});
|
||||
@@ -92,8 +86,7 @@ export async function endTurn(game: string) {
|
||||
export async function lockCard(game: string, cardId: string) {
|
||||
const config = useRuntimeConfig();
|
||||
await $fetch(
|
||||
new URL(`games/${game}/turn/lockCard/${cardId}`, config.public.endpoint)
|
||||
.href,
|
||||
config.public.endpoint + `games/${game}/turn/lockCard/${cardId}`,
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
@@ -104,8 +97,7 @@ export async function lockCard(game: string, cardId: string) {
|
||||
export async function buyCard(game: string, cardId: string) {
|
||||
const config = useRuntimeConfig();
|
||||
await $fetch(
|
||||
new URL(`games/${game}/turn/buyCard/${cardId}`, config.public.endpoint)
|
||||
.href,
|
||||
config.public.endpoint + `games/${game}/turn/buyCard/${cardId}`,
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
@@ -115,13 +107,10 @@ export async function buyCard(game: string, cardId: string) {
|
||||
|
||||
export async function buyGem(game: string) {
|
||||
const config = useRuntimeConfig();
|
||||
await $fetch(
|
||||
new URL(`games/${game}/turn/buyGem`, config.public.endpoint).href,
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
}
|
||||
);
|
||||
await $fetch(config.public.endpoint + `games/${game}/turn/buyGem`, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
});
|
||||
}
|
||||
|
||||
export async function useToken(
|
||||
@@ -132,8 +121,7 @@ export async function useToken(
|
||||
) {
|
||||
const config = useRuntimeConfig();
|
||||
await $fetch(
|
||||
new URL(`games/${game}/turn/useToken/${tokenId}`, config.public.endpoint)
|
||||
.href,
|
||||
config.public.endpoint + `games/${game}/turn/useToken/${tokenId}`,
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
@@ -145,8 +133,7 @@ export async function useToken(
|
||||
export async function lockEffect(game: string, effectId: string) {
|
||||
const config = useRuntimeConfig();
|
||||
await $fetch(
|
||||
new URL(`games/${game}/turn/lockEffect/${effectId}`, config.public.endpoint)
|
||||
.href,
|
||||
config.public.endpoint + `games/${game}/turn/lockEffect/${effectId}`,
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
@@ -161,10 +148,7 @@ export async function makeDiscard(
|
||||
) {
|
||||
const config = useRuntimeConfig();
|
||||
await $fetch(
|
||||
new URL(
|
||||
`games/${game}/turn/makeDiscard/${playerId}`,
|
||||
config.public.endpoint
|
||||
).href,
|
||||
config.public.endpoint + `games/${game}/turn/makeDiscard/${playerId}`,
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
@@ -179,10 +163,7 @@ export async function damagePlayer(
|
||||
) {
|
||||
const config = useRuntimeConfig();
|
||||
await $fetch(
|
||||
new URL(
|
||||
`games/${game}/turn/damagePlayer/${playerId}`,
|
||||
config.public.endpoint
|
||||
).href,
|
||||
config.public.endpoint + `games/${game}/turn/damagePlayer/${playerId}`,
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
@@ -198,10 +179,7 @@ export async function damageChampion(
|
||||
) {
|
||||
const config = useRuntimeConfig();
|
||||
await $fetch(
|
||||
new URL(
|
||||
`games/${game}/turn/damageChampion/${cardId}`,
|
||||
config.public.endpoint
|
||||
).href,
|
||||
config.public.endpoint + `games/${game}/turn/damageChampion/${cardId}`,
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
@@ -213,8 +191,7 @@ export async function damageChampion(
|
||||
export async function discardCard(game: string, cardId: string) {
|
||||
const config = useRuntimeConfig();
|
||||
await $fetch(
|
||||
new URL(`games/${game}/turn/discardCard/${cardId}`, config.public.endpoint)
|
||||
.href,
|
||||
config.public.endpoint + `games/${game}/turn/discardCard/${cardId}`,
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
|
||||
Reference in New Issue
Block a user