auth with api
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import {getConfigValue} from "@brojs/cli";
|
||||
|
||||
export const BASE_API_URL = "http://localhost:8099" + getConfigValue("enterfront.api");
|
||||
|
||||
// fetch(`${BASE_API_URL}/books/list`)
|
||||
|
||||
export async function post(path, body) {
|
||||
const res = await fetch(`${BASE_API_URL}${path}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
|
||||
if (res.status === 200) {
|
||||
const data = await res.json();
|
||||
console.log("Received post:", data);
|
||||
|
||||
return {ok: true, data: data};
|
||||
} else {
|
||||
const errorData = await res.json();
|
||||
console.log("Error during post:", errorData.message);
|
||||
|
||||
return {ok: false, data: errorData};
|
||||
}
|
||||
}
|
||||
|
||||
export async function get(path){
|
||||
const res = await fetch(`${BASE_API_URL}${path}`, {
|
||||
method: "GET"
|
||||
});
|
||||
|
||||
if (res.status === 200) {
|
||||
const data = await res.json();
|
||||
console.log("Received get:", data);
|
||||
|
||||
return {ok: true, data: data};
|
||||
} else {
|
||||
const errorData = await res.json();
|
||||
console.log("Error during get:", errorData.message);
|
||||
|
||||
return {ok: false, data: errorData};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user