diff --git a/packages/client/src/hook/fetcher.ts b/packages/client/src/hook/fetcher.ts index f5e5b0f..0d0ca38 100644 --- a/packages/client/src/hook/fetcher.ts +++ b/packages/client/src/hook/fetcher.ts @@ -1,4 +1,7 @@ +export const BASE_API_URL = 'http://localhost:8080/'; + export async function fetcher(url: string) { - const res = await fetch(url); + const u = new URL(url, BASE_API_URL); + const res = await fetch(u); return res.json(); } diff --git a/packages/client/src/state/user.ts b/packages/client/src/state/user.ts index 5c2fe7f..d610306 100644 --- a/packages/client/src/state/user.ts +++ b/packages/client/src/state/user.ts @@ -1,4 +1,5 @@ import { atom, useAtomValue, setAtomValue } from "../lib/atom.ts"; +import { BASE_API_URL } from "../hook/fetcher.ts"; type LoginLocalStorage = { username: string; @@ -22,8 +23,9 @@ function getUserSessions() { return null; } -async function refresh() { - const res = await fetch("/user/refresh", { +export async function refresh() { + const u = new URL("/user/refresh", BASE_API_URL); + const res = await fetch(u, { method: "POST", }); if (res.status !== 200) throw new Error("Maybe Network Error"); @@ -47,7 +49,8 @@ async function refresh() { } export const doLogout = async () => { - const req = await fetch("/api/user/logout", { + const u = new URL("/user/refresh", BASE_API_URL); + const req = await fetch(u, { method: "POST", }); const setVal = setAtomValue(userLoginStateAtom); @@ -76,7 +79,8 @@ export const doLogin = async (userLoginInfo: { username: string; password: string; }): Promise => { - const res = await fetch("/api/user/login", { + const u = new URL("/user/refresh", BASE_API_URL); + const res = await fetch(u, { method: "POST", body: JSON.stringify(userLoginInfo), headers: { "content-type": "application/json" },