feat(dashboard): add redirects page
This commit is contained in:
parent
32ddb9fae2
commit
cb425fe3cd
7 changed files with 400 additions and 62 deletions
|
|
@ -1,11 +1,40 @@
|
|||
export const TOKEN_KEY = "catalogger-token";
|
||||
|
||||
export default async function apiFetch<T>(
|
||||
method: "GET" | "POST" | "PATCH" | "DELETE",
|
||||
export type HttpMethod = "GET" | "POST" | "PATCH" | "DELETE";
|
||||
|
||||
export async function fastFetch(
|
||||
method: HttpMethod,
|
||||
path: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
body: any = null,
|
||||
) {
|
||||
): Promise<void> {
|
||||
const token = localStorage.getItem(TOKEN_KEY);
|
||||
const headers = {
|
||||
...(body != null
|
||||
? { "Content-Type": "application/json; charset=utf-8" }
|
||||
: {}),
|
||||
...(token ? { Authorization: token } : {}),
|
||||
};
|
||||
|
||||
const reqBody = body ? JSON.stringify(body) : undefined;
|
||||
|
||||
console.debug("Sending", method, "request to", path, "with body", reqBody);
|
||||
|
||||
const resp = await fetch(path, {
|
||||
method,
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
headers,
|
||||
});
|
||||
if (resp.status < 200 || resp.status > 299)
|
||||
throw (await resp.json()) as ApiError;
|
||||
}
|
||||
|
||||
export default async function apiFetch<T>(
|
||||
method: HttpMethod,
|
||||
path: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
body: any = null,
|
||||
): Promise<T> {
|
||||
const token = localStorage.getItem(TOKEN_KEY);
|
||||
const headers = {
|
||||
...(body != null
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue