set BASE URL
This commit is contained in:
parent
02f3cd9bd1
commit
e0cdf51507
@ -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();
|
||||
}
|
||||
|
@ -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<string | LoginLocalStorage> => {
|
||||
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" },
|
||||
|
Loading…
Reference in New Issue
Block a user