feat: add browser workbench and managed local launchers
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
export async function api<T>(path: string, options: RequestInit = {}): Promise<T> {
|
||||
const response = await fetch('/api' + path, { ...options, headers: options.body instanceof FormData ? options.headers : { 'Content-Type': 'application/json', ...options.headers } });
|
||||
if (!response.ok) {
|
||||
const body = await response.json().catch(() => ({ detail: `请求失败 (${response.status})` }));
|
||||
throw new Error(typeof body.detail === 'string' ? body.detail : `参数无效 (${response.status})`);
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
export const post = <T,>(path: string, body: unknown = {}) => api<T>(path, { method: 'POST', body: JSON.stringify(body) });
|
||||
Reference in New Issue
Block a user