Working on upload images and tilemap
This commit is contained in:
@@ -8,7 +8,7 @@ export async function get(endpoint: string, params: Record<string, any> = {}): P
|
||||
// Remove undefined params
|
||||
Object.keys(params).forEach((key) => params[key] === undefined && delete params[key]);
|
||||
const urlParams = new URLSearchParams(params);
|
||||
const url = urlParams ? `${baseURL}/${endpoint}?${urlParams}` : `${baseURL}/${endpoint}`;
|
||||
const url = urlParams && urlParams.size > 0 ? `${baseURL}/${endpoint}?${urlParams}` : `${baseURL}/${endpoint}`;
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
credentials: 'include'
|
||||
@@ -16,11 +16,15 @@ export async function get(endpoint: string, params: Record<string, any> = {}): P
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function post(endpoint: string, body = {}): Promise<Response> {
|
||||
interface PostOptions {
|
||||
headers?: Record<string, any>;
|
||||
}
|
||||
|
||||
export async function post(endpoint: string, body = {}, options?: PostOptions): Promise<Response> {
|
||||
const url = `${baseURL}/${endpoint}`;
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
headers: options?.headers || {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
credentials: 'include',
|
||||
|
||||
Reference in New Issue
Block a user